0Pricing
SwiftUI Academy · درس

أساسيات GeometryReader

قِس المساحة المتاحة لتحديد حجم المحتوى

أساسيات GeometryReader درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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

الأسئلة الشائعة

هل درس «أساسيات GeometryReader» مجاني؟

نعم — نص درس «أساسيات GeometryReader» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

ماذا ستتعلم في «أساسيات GeometryReader»؟

قِس المساحة المتاحة لتحديد حجم المحتوى تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟

لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «أساسيات GeometryReader»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟

نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. أساسيات GeometryReader
  2. أدلة المحاذاة المخصصة
  3. بروتوكول Layout
  4. بناء تخطيط Flow
← العودة إلى SwiftUI Academy