InfiniteScrollViews 包含了一些有用的 SwiftUI、UIKit 和 AppKit 组件。
因为我们无法真正生成无限多的视图并将它们放入 ScrollView 中,所以我们需要使用**一种递归逻辑**。InfiniteScrollView 和 PagedInfiniteScrollView 可以显示“无限”内容,这要归功于这种逻辑。
InfiniteScrollView(
frame: CGRect,
changeIndex: ChangeIndex,
content: @escaping (ChangeIndex) -> Content,
contentFrame: @escaping (ChangeIndex) -> CGRect,
increaseIndexAction: @escaping (ChangeIndex) -> ChangeIndex?,
decreaseIndexAction: @escaping (ChangeIndex) -> ChangeIndex?,
orientation: UIInfiniteScrollView<ChangeIndex>.Orientation, // or NSInfiniteScrollView<ChangeIndex>.Orientation
refreshAction: ((@escaping () -> Void) -> ())? = nil,
spacing: CGFloat = 0,
updateBinding: Binding<Bool>? = nil
)
content: { currentDate in
MonthView(date: currentDate)
.padding()
}
increaseIndexAction: { currentDate in
return Calendar.current.date(byAdding: .init(month: 1), to: currentDate)
}
decreaseIndexAction: { currentDate in
return Calendar.current.date(byAdding: .init(month: -1), to: currentDate)
}
可以在 InfiniteScrollViewsExample 中找到其他示例。
SwiftUI 中 ScrollView 组件的无限版本。
SwiftUI 中分页 TabView 组件的无限版本。
UIKit 中 UIScrollView 组件的无限版本。
UIKit 中 UIPageViewController 的一个更简单的版本。
AppKit 中 NSScrollView 组件的无限版本。
AppKit 中 NSPageController 组件的无限版本。