0Pricing
SwiftUI Academy · Lekcja

Detenty i wskaźniki przeciągania

Zmieniaj rozmiar arkuszy za pomocą detentów prezentacji

Detenty i wskaźniki przeciągania to bezpłatna lekcja SwiftUI Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej SwiftUI Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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! 🎉

Często zadawane pytania

Czy lekcja „Detenty i wskaźniki przeciągania” jest bezpłatna?

Tak — pełny tekst „Detenty i wskaźniki przeciągania” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu SwiftUI Academy, przejdź na CoddyKit PRO. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Detenty i wskaźniki przeciągania”?

Zmieniaj rozmiar arkuszy za pomocą detentów prezentacji Ćwiczysz SwiftUI Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć SwiftUI Academy?

Nie wymagamy żadnego doświadczenia. SwiftUI Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Detenty i wskaźniki przeciągania”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji SwiftUI Academy?

Tak. Każda lekcja SwiftUI Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Prezentowanie arkusza
  2. Detenty i wskaźniki przeciągania
  3. Alerty z akcjami
  4. Okna dialogowe potwierdzenia
← Powrót do SwiftUI Academy