MXScroll
MXScroll 是一个框架,让您更容易创建混合滚动视图。您只需提供数据源,无需考虑页面组成。数据源可以通过 Storyboard 或程序性提供。
结构
示例
要运行示例项目,请克隆仓库,然后先从 Example 目录运行 pod install
WKWebView | UIScrollView | UIView |
---|---|---|
![]() |
![]() |
![]() |
要求
- Xcode 9+
- Swift 4.0+
- iOS 10.0+
安装
Swift 兼容性
使用 Swift 4.0,请使用 MXScroll v.0.1.0。
使用 Swift 4.1,请使用 MXScroll v.0.1.2。
CocoaPods
MXScroll 通过 CocoaPods 提供。要安装,请简单地将以下行添加到您的 Podfile 中
pod 'MXScroll'
使用方法
简单
1. 首先你应该
import MXScroll
2. 准备头部
let header = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "HeaderViewController")
如果 WKWebView
、UIWebView
或 UIScrollView
在 HeaderVC 中,你应该实现 MXViewControllerViewSource
。
extension HeaderViewController:MXViewControllerViewSource{
func headerViewForContentOb() -> UIView? {
return webView
}
}
3. 准备内容
let child1 = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "ChildViewController")
如果 UITableView
或 UIScrollView
位于 ContentVC 中,您应该实现 MXViewControllerViewSource
extension ChildViewController:MXViewControllerViewSource{
func viewForMixToObserveContentOffsetChange() -> UIView {
return self.tableView
}
}
4. 准备分段
您可以使用由 MXScroll
提供的 MSSegmentControl
let segment = MSSegmentControl(sectionTitles: ["1", "2"])
5. 混合
let header = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "HeaderViewController")
let child1 = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "ChildViewController")
let child2 = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "SecondViewController")
let segment = MSSegmentControl(sectionTitles: ["1", "2"])
let mx = MXViewController<MSSegmentControl>.init(headerViewController: header, segmentControllers: [child1, child2], segmentView: segment)
navigationController?.pushViewController(mx, animated: true)
分段
如果您想使用自定义分段,只需实现 MXSegmentProtocol
extension MSSegmentControl: MXSegmentProtocol {
// segment change to tell vc
public var change: ((Int) -> Void) {
get {
return self._didIndexChange
}
set {
self._didIndexChange = newValue
}
}
// vc change callback method
public func setSelected(index: Int, animator: Bool) {
self.setSelected(forIndex: index, animated: animator, shouldNotify: true)
}
}
作者
cillyfly, [email protected]
许可证
MXScroll 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。