0Pricing
SwiftUI Academy · Lección

Fundamentos de GeometryReader

Mida el espacio disponible para dimensionar el contenido.

Fundamentos de GeometryReader es una lección gratuita de SwiftUI Academy en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de SwiftUI Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de SwiftUI Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en 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.top

Use 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. 🎉

Preguntas frecuentes

¿La lección «Fundamentos de GeometryReader» es gratis?

Sí — el texto completo de «Fundamentos de GeometryReader» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de SwiftUI Academy, actualiza a CoddyKit PRO. El curso de SwiftUI Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Fundamentos de GeometryReader»?

Mida el espacio disponible para dimensionar el contenido. Practicas SwiftUI Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar SwiftUI Academy?

No se requiere experiencia previa. SwiftUI Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.

¿Cuánto tiempo toma la lección «Fundamentos de GeometryReader»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de SwiftUI Academy?

Sí. Cada lección de SwiftUI Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Fundamentos de GeometryReader
  2. Guías de alineación personalizadas
  3. El protocolo Layout
  4. Crear un Flow Layout
← Volver a SwiftUI Academy