MXScroll is a framework that lets you create mix scroll view easier. you can just provide the datasource and do not need to consider the page composition. the datasource can be provided by storyboard or programmatically.
To run the example project, clone the repo, and run pod install
from the Example directory first.
WKWebView | UIScrollView | UIView |
---|---|---|
![]() |
![]() |
![]() |
- Xcode 9+
- Swift 4.0+
- iOS 10.0+
To work with Swift 4.0 use MXScroll v.0.1.0.
To work with Swift 4.1 use MXScroll v.0.1.2.
To work with Swift 5.0 use MXScroll v.0.1.3
MXScroll is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MXScroll'
import MXScroll
let header = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "HeaderViewController")
if WKWebView
, UIWebView
or UIScrollView
is in HeaderVC, you should implement MXViewControllerViewSource
.
extension HeaderViewController:MXViewControllerViewSource{
func headerViewForContentOb() -> UIView? {
return webView
}
}
let child1 = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "ChildViewController")
if UITableView
or UIScrollView
is in ContentVC, you should implement MXViewControllerViewSource
extension ChildViewController:MXViewControllerViewSource{
func viewForMixToObserveContentOffsetChange() -> UIView {
return self.tableView
}
}
You can use the MSSegmentControl
provide by MXScroll
let segment = MSSegmentControl(sectionTitles: ["1", "2"])
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)
If you want to use the custom Segment,Just implementMXSegmentProtocol
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, cillyfly@163.com
MXScroll is available under the MIT license. See the LICENSE file for more info.