LTPageController是基于UIScrollView的封装。
* 提供两种基础的翻页动画的实现: 正常、层叠
* 继承协议可以自定义动画
* 提供中心缓存策略,提高运行效率,可自定义缓存的大小
需求
- Xcode 9.0+
- Swift 4.2+
- iOS 8.0+
安装
-
Pod
LTPageController 可通过 CocoaPods 获得。要安装它,只需将以下行添加到 Podfile 中
pod 'LTPageController'
使用
-
示例图
-
常规使用
let vc = LTPageController(delegate: self, dataSource: self, animation: LTPageControllerNormalAnimation.self, direction: .vertical)
-
自定义动画
继承 LTPageControllerAnimationProtocol 协议,自定义 Animation
-
初始化配置
public class func config(_ pageController: LTPageController) { pageController.scrollView.isPagingEnabled = true }
-
定义滑动时 Controller 展示的位置
public class func rect(_ pageController: LTPageController, contentController: UIViewController, type: LTPageController.ScrollType, index: Int) -> CGRect { let width = pageController.contentWidth let height = pageController.contentHeight switch pageController.direction { case .horizontal: let originX = width * CGFloat(index) return CGRect(x: originX, y: 0, width: width, height: height) case .vertical: let originY = height * CGFloat(index) return CGRect(x: 0, y: originY, width: width, height: height) } }
-
-
修改当前选中
setController(currentIndex, animated: false)
-
支持修改的属性
pageVC.numOfPages = 7 // 页数 pageVC.cacheSize = 3 // 缓存大小
-
代理
index 发生改变 回调
func indexChanged(_ pageController: LTPageController, index: Int)
-
数据源
根据 index 返回对应的 Controller
func controller(_ pageController: LTPageController, index: Int) -> UIViewController?
许可证
LTPageController 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。