0Pricing
SwiftUI Academy · درس

‏ScrollView Reader والمراسي

انتقل برمجيًا إلى عناصر محددة

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

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

Jumping to Content

Sometimes you need to scroll to a specific item in code, like a Back to Top button. ScrollViewReader makes that possible. 🎯

Wrap the ScrollView

Place a ScrollViewReader around your ScrollView; it hands you a proxy you use to control scrolling.

ScrollViewReader { proxy in
    ScrollView {
        Content()
    }
}

Tag Each Item

Give scrollable items a unique id so the reader knows exactly where to jump when you ask it to.

ForEach(items) { item in
    Row(item).id(item.id)
}

Call scrollTo

The proxy has one key method: scrollTo. Pass an id and the ScrollView glides that item into view.

proxy.scrollTo(42)

Animate the Jump

Wrap the call in withAnimation so the scroll glides smoothly instead of snapping instantly to the target.

withAnimation {
    proxy.scrollTo(42)
}

Anchor the Position

The anchor argument decides where the item lands: .top pins it to the top, .center to the middle.

proxy.scrollTo(42, anchor: .top)

Back to Top Button

A common pattern is a button that calls scrollTo on the first item id to whisk the user back up.

Button("Top") {
    proxy.scrollTo(firstID, anchor: .top)
}

Jump on Appear

Call scrollTo inside onAppear to open a long list already scrolled to the user latest unread row.

.onAppear {
    proxy.scrollTo(lastReadID)
}

IDs Must Match

If scrollTo does nothing, check that the id you pass exactly matches an id set on a visible item.

Pair with State

Trigger scrolling from a @State change, like a search result selection, to guide the user automatically.

onChange(of: selected) { id in
    proxy.scrollTo(id)
}

Effortless Navigation

With ScrollViewReader and anchors, long screens feel navigable and friendly instead of an endless swipe. ✨

Quick Check

Think about how you move to a specific row.

Recap

You learned to use ScrollViewReader, tag items with ids, and call scrollTo with anchors to jump anywhere in code. 🎉

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

هل درس «‏ScrollView Reader والمراسي» مجاني؟

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

ماذا ستتعلم في «‏ScrollView Reader والمراسي»؟

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

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

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

كم من الوقت يستغرق درس «‏ScrollView Reader والمراسي»؟

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

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

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

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

  1. ‏ScrollView الأفقي والرأسي
  2. ‏LazyVStack وLazyHStack
  3. شبكات متكيفة باستخدام LazyVGrid
  4. ‏ScrollView Reader والمراسي
← العودة إلى SwiftUI Academy