0Pricing
SwiftUI Academy · Lekcja

Prezentowanie arkusza

Wyświetl widok modalny z arkuszem i powiązaniem

Prezentowanie arkusza to bezpłatna lekcja SwiftUI Academy na CoddyKit. To lekcja 1 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 Is a Sheet?

A sheet is a card that slides up from the bottom to show extra content, like a form or detail, without leaving your current screen. 📄

Sheets Need a Trigger

A sheet appears when a boolean state flips to true. You store that flag in your view and flip it when the user taps something.

@State private var showSheet = false

The .sheet Modifier

You attach .sheet to a view and bind it to your boolean. When the value is true, SwiftUI presents the content you return.

.sheet(isPresented: $showSheet) {
    Text("Hello from the sheet!")
}

The Dollar Sign Binding

The $ before showSheet passes a two-way binding, so SwiftUI can both read the flag and reset it to false when the sheet closes.

.sheet(isPresented: $showSheet) { DetailView() }

Opening the Sheet

Set the boolean to true from a button action and the sheet animates up automatically. You never call a present function yourself. ✨

Button("Show Details") {
    showSheet = true
}

Putting It Together

Combine the button, the state, and the .sheet modifier on one view and you have a working modal in just a few lines.

Button("Open") { showSheet = true }
    .sheet(isPresented: $showSheet) {
        Text("Sheet content")
    }

Dismissing a Sheet

Users can swipe a sheet down to close it. To dismiss it in code, read the dismiss action from the environment inside the sheet.

@Environment(\.dismiss) private var dismiss

Calling dismiss()

Give the sheet a Done button that calls dismiss(). This is the polite way to let users finish and return to the main screen.

Button("Done") { dismiss() }

Sheets Get Their Own State

A sheet is a normal SwiftUI view, so it can hold its own state, modifiers, and even another sheet. Treat it like any other screen.

Presenting With an Item

Use sheet(item:) when the sheet depends on a selected value. SwiftUI shows the sheet whenever that optional item is non-nil.

.sheet(item: $selectedBook) { book in
    BookDetail(book: book)
}

One Sheet at a Time

A view shows one sheet per modifier. For several modals, use separate flags or item bindings so they never collide on screen.

Quick Check

How do you tell SwiftUI to present a sheet?

Recap: Sheets

You learned that a sheet slides up from a boolean flag, attaches with .sheet, and closes via swipe or the dismiss action. Nice work! 🎉

Często zadawane pytania

Czy lekcja „Prezentowanie arkusza” jest bezpłatna?

Tak — pełny tekst „Prezentowanie arkusza” 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 „Prezentowanie arkusza”?

Wyświetl widok modalny z arkuszem i powiązaniem Ć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 1 z 4.

Ile czasu zajmuje lekcja „Prezentowanie arkusza”?

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