类似于淘票票首页,抖音、简书个人主页的嵌套滚动库
- iOS 9.0+
- Swift 4.2+
- Xcode 10+
use_frameworks!
pod 'Aquaman'
Add the following dependency to your Package.swift manifest:
.package(url: "https://github.com/bawn/Aquaman.git", .branch("master")),
首先需要导入 Aquaman
import Aquaman
import Aquaman
class PageViewController: AquamanPageViewController {
// ...
}
override func numberOfViewControllers(in pageController: AquamanPageViewController) -> Int {
return count
}
override func pageController(_ pageController: AquamanPageViewController, viewControllerAt index: Int) -> (UIViewController & AquamanChildViewController) {
// ...
return viewController
}
注意: 所提供的 viewController 必须都遵守 AquamanChildViewController
协议,并实现 func aquamanChildScrollView() -> UIScrollView
方法
import Aquaman
class ChildViewController: UIViewController, AquamanChildViewController {
@IBOutlet weak var tableView: UITableView!
func aquamanChildScrollView() -> UIScrollView {
return tableView
}
// ...
}
override func headerViewFor(_ pageController: AquamanPageViewController) -> UIView {
return HeaderView()
}
override func headerViewHeightFor(_ pageController: AquamanPageViewController) -> CGFloat {
return headerViewHeight
}
override func menuViewFor(_ pageController: AquamanPageViewController) -> UIView {
return menuView
}
override func menuViewHeightFor(_ pageController: AquamanPageViewController) -> CGFloat {
return menuViewHeight
}
Aquaman 采用的是 menuView 和主体功能分离的设计,以满足 menuView 有时候需要深度定制的需求,所以 menuView 需要开发者自己实现,当然这里也提供了现成的 menuView 库:Trident
override func pageController(_ pageController: AquamanPageViewController, contentScrollViewDidScroll scrollView: UIScrollView) {
menuView.updateLayout(scrollView)
}
override func pageController(_ pageController: AquamanPageViewController, didDisplay viewController: (UIViewController & AquamanChildViewController), forItemAt index: Int) {
menuView.checkState(animation: true)
}
由于 menuView 和 pageController 不存在强关联关系,所以在滚动的时候需要更新 menuView 布局,在显示相应的 viewController 的时候需要检查 menuView 的状态,具体参考 demo
Follow these 4 steps to run Example project:
- Clone Aquaman repository
- Run the
pod install
command - Open Aquaman workspace
- Run the Aquaman-Demo project.
Aquaman is released under the MIT license. See LICENSE for details.