Fundamentos do GeometryReader
Meça o espaço disponível para dimensionar o conteúdo.
Fundamentos do GeometryReader é 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.
Measuring Space
Sometimes a view needs to know how big its slot is. GeometryReader hands you the exact size and position of the space it occupies. 📐
It Is a Container
A GeometryReader is a view whose body is a closure receiving a proxy that describes the available space.
GeometryReader { proxy in
Text("Hi")
}The Proxy
That closure parameter is a GeometryProxy. It carries the size, safe-area insets, and frame of the reader.
GeometryReader { proxy in
let w = proxy.size.width
Color.blue.frame(width: w)
}Reading the Size
The most common move is proxy.size, a CGSize giving you the width and height you can fill.
GeometryReader { proxy in
Text("\(proxy.size.width)")
}Half the Width
Use the measured width for proportional sizing, like making a bar exactly half of the available width.
GeometryReader { proxy in
Color.green
.frame(width: proxy.size.width / 2)
}It Fills by Default
A GeometryReader greedily takes all the space its parent offers, so its children align to the top-left unless you center them.
Centering Content
Because content pins top-left, wrap it or add a frame with alignment to center children inside the reader.
GeometryReader { proxy in
Text("Center")
.frame(width: proxy.size.width,
height: proxy.size.height)
}Global Coordinates
Ask for a view position in the window with proxy.frame(in: .global), handy for scroll effects and overlays.
let f = proxy.frame(in: .global)
Text("\(f.minY)")Safe Area Insets
The proxy also exposes safeAreaInsets, so you can respect notches and home indicators in custom layouts.
let top = proxy.safeAreaInsets.topUse It Sparingly
A GeometryReader changes layout behavior, so reach for it only when you truly need measurements, not as a default wrapper. ⚠️
Scroll-Driven Effects
Combined with a ScrollView, reading each item frame lets you build parallax and fade effects tied to scroll position.
Quick Check
Recall what the closure hands you.
Recap
You can now read available space with GeometryReader, size views proportionally, and read frames for scroll-aware effects. 🎉
Perguntas Frequentes
A aula “Fundamentos do GeometryReader” é grátis?
Sim — o texto completo de “Fundamentos do GeometryReader” é 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 “Fundamentos do GeometryReader”?
Meça o espaço disponível para dimensionar o conteúdo. 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 “Fundamentos do GeometryReader”?
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
- Fundamentos do GeometryReader
- Guias de Alinhamento Personalizadas
- O Protocolo de Layout
- Criando um Layout de Fluxo