0Pricing
SwiftUI Academy · Aula

Detents e Indicadores de Arraste

Redimensione sheets com detents de apresentação.

Detents e Indicadores de Arraste é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 2 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 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! 🎉

Perguntas Frequentes

A aula “Detents e Indicadores de Arraste” é grátis?

Sim — o texto completo de “Detents e Indicadores de Arraste” é 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 “Detents e Indicadores de Arraste”?

Redimensione sheets com detents de apresentação. 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 2 de 4.

Quanto tempo leva a aula “Detents e Indicadores de Arraste”?

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