PageController
PageController 是一个无限翻页控制器,内容滚动和标题栏滚动有延迟。然后它提供用户交互,使流畅且轻松地移动。这是用 Swift 编写的 iOS。
要求
PageController | Xcode | Swift |
---|---|---|
0.7.x+ | 9.4 | 4.1 |
0.6.x | 9.2 | 4.0 |
0.5.x | 8.2 | 3.0 |
0.4.x | 8.0 | 2.2 |
0.3.x | 7.0+ | 2.0 |
0.2.0 | 6.4 | 1.2 |
特点
- 从 DCScrollView 继承
- 使用
UIViewController
,而不是像UITabBarController
一样的UIView
- 支持关于 MenuCell 的 AutoLayout
- 使用 Delegate 处理更改当前视图控制器。
- 滚动流畅且轻松
- 在滚动内容时保持流畅
安装
CocoaPods
pod 'PageController'
Carthage
要使用Carthage将PageController集成到您的Xcode项目中,在您的《Cartfile》中指定它。
github "hirohisa/PageController" ~> 0.7.1
使用方法
viewControllers
类型为[UIViewController],元素必须有标题。
import PageController
class CustomViewController: PageController {
override func viewDidLoad() {
super.viewDidLoad()
viewControllers = createViewControllers()
}
func createViewControllers() -> [UIViewController] {
let names = [
"favorites",
"recents",
"contacts",
"history",
"more",
]
return names.map { name -> UIViewController in
let viewController = ContentViewController()
viewController.title = name
return viewController
}
}
}
菜单栏
可以更改backgroundColor和frame。如果您更改MenuBarCell.height,则重写frameForMenuBar
并设置高度。
/// backgroudColor
menuBar.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.9)
/// skip to auto-select after scrolling
menuBar.isAutoSelectDidEndUserInteractionEnabled = false
/// frame, override this function
override var frameForMenuBar: CGRect {
let frame = super.frameForMenuBar
return CGRect(x: frame.minX, y: frame.minY, width: frame.width, height: 60)
}
MenuBarCell
可以使用支持Custom Cell的MenuBarCellable
协议。
public protocol MenuBarCellable {
var index: Int { get set }
func setTitle(_ title: String)
func setHighlighted(_ highlighted: Bool)
func prepareForReuse()
}
public func register(_ cellClass: MenuBarCellable) {
guard let cellClass = cellClass as? UIView.Type else { fatalError() }
self.cellClass = cellClass
}
public func register(_ nib: UINib) {
self.nib = nib
}
MenuBarCellable
public protocol MenuBarCellable {
// it's used by PageController
var index: Int { get set }
// it is used to set to Label.text, caused by deprecating MenuCell over 0.7
func setTitle(_ title: String)
// it's instead of `updateData` over 0.7,
func setHighlighted(_ highlighted: Bool)
// Called by the menu bar on creating the instance.
func prepareForUse()
}
许可协议
PageController受MIT许可协议保护。