0Pricing
SwiftUI Academy · レッスン

デタントとドラッグインジケーター

表示位置のデタントでシートのサイズを変更します。

「デタントとドラッグインジケーター」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSwiftUI Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 SwiftUI Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

What Are Detents?

A detent is a stopping height a sheet can rest at, like half-open or full. They let users resize the sheet by dragging it. 📏

The presentationDetents Modifier

Add presentationDetents inside the sheet content to list the heights it can snap to. Pass a set of detents to enable resizing.

.presentationDetents([.medium, .large])

Medium and Large

The two built-in detents are .medium, about half the screen, and .large, nearly full height. Offer both so users pick what fits.

.presentationDetents([.medium, .large])

A Fixed Height Detent

Use .height to pin a sheet to an exact point size. This is great for short forms that should not grow taller than needed.

.presentationDetents([.height(220)])

A Fraction Detent

The .fraction detent sizes the sheet to a share of the screen, like a third. It adapts nicely across different device sizes.

.presentationDetents([.fraction(0.33)])

The Drag Indicator

The little grabber bar at the top is the drag indicator. It hints that the sheet can be pulled up, down, or dismissed.

Showing the Grabber

Add presentationDragIndicator set to .visible to always show the grabber, even when only one detent is available.

.presentationDragIndicator(.visible)

Combining Modifiers

Detents and the drag indicator stack together on the sheet content. Apply both for a resizable sheet with a clear grab handle. ✨

ContentView()
    .presentationDetents([.medium, .large])
    .presentationDragIndicator(.visible)

Tracking the Selected Detent

Bind presentationDetents to a state value to know which height the user chose, so your layout can react to the current size.

.presentationDetents([.medium, .large], selection: $detent)

Why Detents Matter

Detents keep sheets non-blocking. A medium sheet lets users glance at content while still seeing the screen behind it.

One Detent, No Resize

If you pass a single detent, the sheet stays one fixed height and cannot be resized, though it can still be swiped to dismiss.

.presentationDetents([.medium])

Quick Check

Which modifier lets a sheet snap to multiple heights?

Recap: Detents

You can now resize sheets with detents like .medium, .large, and .fraction, plus show a grabber with the drag indicator. Great progress! 🎉

よくある質問

「デタントとドラッグインジケーター」レッスンは無料ですか?

はい。「デタントとドラッグインジケーター」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。

「デタントとドラッグインジケーター」で何を学びますか?

表示位置のデタントでシートのサイズを変更します。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

SwiftUI Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「デタントとドラッグインジケーター」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このSwiftUI Academyレッスンでコードを書いて実行できますか?

はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. シートを表示する
  2. デタントとドラッグインジケーター
  3. アクション付きアラート
  4. 確認ダイアログ
← SwiftUI Academyに戻る