BouncyPageViewController
受 Stan Yakushevish 的运动设计启发的具有弹跳效果的页面视图控制器。
![]() |
![]() |
---|
快速入门
UIViewControllers
队列
创建要显示的 let pagesQueue: [UIViewController]() = ... // your view controllers here
BouncyPageViewController
通过传递初始视图控制器创建 let pageViewController = BouncyPageViewController(initialViewControllers: Array(pagesQueue[0...1]))
为提供下一页/上一页视图控制器分配闭包
pageViewController.viewControllerAfterViewController = self.viewControllerAfterViewController
pageViewController.viewControllerBeforeViewController = self.viewControllerBeforeViewController
从队列中销售下一个 ViewController
func viewControllerAfterViewController(prevVC: UIViewController) -> UIViewController? {
if let idx = self.pagesQueue.index(of: prevVC), idx + 1 < self.pagesQueue.count {
return self.pagesQueue[idx + 1]
}
return nil
}
didScroll
回调闭包
分配 pageViewController.didScroll = self.pageViewControllerDidScroll
offset
和 progress
更新 UI
使用 func pageViewControllerDidScroll(pageViewController: BouncyPageViewController, offset: CGFloat, progress: CGFloat) {
for vc in pageViewController.visibleControllers() {
let vc = (vc as! ViewController)
vc.progress = progress
}
}
配置
页面之间重叠多少,更多内缩 - 更高级的弹跳
public var pageContentInset: CGFloat = 30
释放页面时弹跳动画持续多长时间
public var pageBounceAnimationDuration: TimeInterval = 1
滚动到最后一个页面多远才能使其返回到页面的一半
public var overscrollBounceMultiplier: CGFloat = 0.5
示例
要运行示例项目,请克隆仓库
$ pod install
并像往常一样运行。
安装
需求
iOS 9+
Swift 3
Carthage
要使用最新版本,请将以下内容添加到Cartfile
git "https://github.com/BohdanOrlov/BouncyPageViewController"
然后在终端中运行
$ carthage update
CocoaPods
BouncyPageViewController 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "BouncyPageViewController"
由于 Swift 3,您必须将此内容添加到 Podfile 的末尾
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
作者
Bohdan Orlov,[email protected]
许可协议
BouncyPageViewController 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。