2

On iOS 16.3 the ScrollView component can enable paging by setting the following:

UIScrollView.appearance().isPagingEnabled = true

However, after updating to iOS 16.4, this no longer enables paging on the ScrollView. Are there any workarounds to make this solution work? or are there alternative ways to build vertical paging in SwiftUI? I'm familiar with workarounds using TabView but I cannot use that in this project for other reasons.

John
  • 188
  • 1
  • 3
  • 10
  • Have you tried setting the property directly on the scrollview instance rather than on all scrollviews via the appearance proxy? – Paulw11 Apr 05 '23 at 00:32
  • @Paulw11 SwiftUI's `ScrollView` does not have a `isPagingEnabled` property – John Apr 05 '23 at 00:39
  • 2
    Sorry, I missed the SwiftUI reference. I guess it was an undocumented effect that no longer works. – Paulw11 Apr 05 '23 at 00:44
  • There might be some solutions here https://stackoverflow.com/questions/56893240/is-there-any-way-to-make-a-paged-scrollview-in-swiftui ? – Paulw11 Apr 05 '23 at 00:50
  • @John I'm seeing the problem on simulators running 16.4, but not devices running 16.5 (and there is no simulator for 16.5). Were you able to confirm this problem exists on devices running 16.4, and not just the simulator? – James Aug 09 '23 at 17:43

2 Answers2

1

Horizontal/Vertical paging in iOS 17

From iOS 17, you don't need to tweak the UIKit appearance. All you need to do is applying the following modifier on the ScrollView:

.scrollTargetBehavior(.paging)

This works on both horizontal and vertical scrollViews

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278
0

Try to use CollectionView wrapper. you can follow this link already implemented.