Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

SwiftUI ScrollPosition: Advanced Scroll Control in iOS 18

The article introduces SwiftUI’s new ScrollPosition type in iOS 18, explains how to track and set scroll locations using offsets, edges, and view identifiers, demonstrates animated programmatic scrolling, reading position properties, detecting user‑driven scrolling, and provides a complete runnable example for fluid UI design.

This article explores the new ScrollPosition type introduced in SwiftUI for iOS 18, providing developers with more granular control over scroll view behavior. The content covers how to use ScrollPosition to track and set scroll positions using various methods including offsets, edges, and view identifiers.

The article begins with an introduction to the new features announced at WWDC 24, then demonstrates basic usage of scrollPosition modifier with view identifiers. It progresses to show how ScrollPosition allows combining offsets, scroll view edges, and view identifiers for more precise control.

Key topics include: using ScrollPosition with different edge alignments (top, bottom), adding animations to programmatic scrolling using the animation modifier, scrolling to specific items using view identifiers with anchor points, and scrolling to specific points using CGPoint coordinates. The article also covers reading scroll positions through ScrollPosition's optional edge, point, and viewID properties, and detecting user-initiated scrolling using the isPositionedByUser property.

Practical examples include a complete runnable code sample that demonstrates reading and displaying scroll offset using onScrollGeometryChange modifier, showing how to track contentBounds.origin for real-time position updates. The article concludes by highlighting how these new features enable developers to create more fluid and intuitive user interfaces with enhanced scroll control capabilities.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

SWIFTSwiftUIiOS 18User Interfacescroll-viewScrollPositionWWDC 24

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion