测试已验证 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布最新发布 | 2016年11月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Mycose 维护。
要运行示例项目,首先克隆仓库,然后从示例目录运行 pod install
,或者访问 此处。
对于无限轮播滚动等,我发现只有两种可能性:1- 使用 UICollectionView 或 UITableView,并将元素数量设得非常高,然后在开始时从中部滚动,并通过 / 和 % 来获得正确的索引,每次都保持正确的索引 2- 假设您有一个滚动视图,页面如下所示:1 2 3 4 5。基本上,您只想有 5 1 2 3 4 5 1 的排列,当用户滚动并到达第一个 1 或第二个 5 时,您希望无缝且无动画地将滚动回到开始或结束,这会产生无限的错觉,因为您实际上会一直在同一些元素上滚动
在这个项目中,我采用了第二种方法
CMLazyScrollViewController 是一个 UIViewController,它包含一个 UIScrollView 和 UIPageControl。CMLazyScrollViewController 的代理要求 UIViewController 在页面上放置视图。它有一个懒加载选项(内存中只有 3 个视图控制器)和无限模式。
// properties for the scrollview
public var isPagingEnable = true
public var isHorizontalScrollIndicatorHidden = false
public var isVerticalScrollIndicatorHidden = false
// scroll view delegate which will be call after every delegate function
public var scrollDelegate : UIScrollViewDelegate?
let carousel = CMLazyScrollViewController()
carousel.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
carousel.infinite = true
carousel.isPagingEnable = true
carousel.delegate = self
self.addChildViewController(carousel)
self.view.addSubview(carousel.view)
// ask for the number of view in the controller
func numberOfViewControllersIn(scrollViewController : CMLazyScrollViewController) -> Int
// request a view controller to show at the index
func viewControllerIn(scrollViewController : CMLazyScrollViewController, atIndex: Int) -> UIViewController
CMLazyScrollViewController 可通过 CocoaPods 使用。要安装它,只需将以下行添加到您的 Podfile 中
pod 'CMLazyScrollViewController'
Mycose, [email protected]
CMLazyScrollViewController 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。