0Pricing
SwiftUI Academy · Aula

Apresentando uma Sheet

Exiba uma visualização modal com sheet e uma binding.

Apresentando uma Sheet é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de SwiftUI Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de SwiftUI Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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

Perguntas Frequentes

A aula “Apresentando uma Sheet” é grátis?

Sim — o texto completo de “Apresentando uma Sheet” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de SwiftUI Academy, atualize para CoddyKit PRO. O curso de SwiftUI Academy inclui 4 aulas no total.

O que vou aprender em “Apresentando uma Sheet”?

Exiba uma visualização modal com sheet e uma binding. Você pratica SwiftUI Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar SwiftUI Academy?

Nenhuma experiência prévia é necessária. SwiftUI Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “Apresentando uma Sheet”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de SwiftUI Academy?

Sim. Cada aula de SwiftUI Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Apresentando uma Sheet
  2. Detents e Indicadores de Arraste
  3. Alertas com Ações
  4. Diálogos de Confirmação
← Voltar para SwiftUI Academy