34

GitHub - bawn/Aquaman: A pure-Swift library for nested display of horizontal and...

 5 years ago
source link: https://github.com/bawn/Aquaman
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

Aquaman

License MIT Pod version Platform info Support Swift 4.2

A pure-Swift library for nested display of horizontal and vertical scrolling views.

demo

Requirements

  • iOS 9.0+
  • Swift 4.2+
  • Xcode 10+

Installation

CocoaPods (recommended)

use_frameworks!

pod 'Aquaman'

Usage

First make sure to import the framework:

import Aquaman

Basically, we just need to provide the list of child view controllers to show. Then call some necessary methods.

Let's see the steps to do this:

Create a AquamanPageViewController subclass

import Aquaman

class PageViewController: AquamanPageViewController {
  // ...
}

Provide the view controllers that will appear embedded into the AquamanPageViewController

override func numberOfViewControllers(in pageController: AquamanPageViewController) -> Int {
    return count
}
    
override func pageController(_ pageController: AquamanPageViewController, viewControllerAt index: Int) -> (UIViewController & AquamanChildViewController) {
    // ...
    return viewController
}
    

Every UIViewController that will appear within the AquamanPageViewController should conform to AquamanChildViewController by implementing func aquamanChildScrollView() -> UIScrollView and call func childScrollViewDidScroll(_ scrollView: UIScrollView) in func scrollViewDidScroll(_ scrollView: UIScrollView)

import Aquaman
class ChildViewController: UIViewController, AquamanChildViewController {

    @IBOutlet weak var tableView: UITableView!
    func aquamanChildScrollView() -> UIScrollView {
        return tableView
    }
    // ...
}
extension ChildViewController: UITableViewDelegate, UITableViewDataSource {
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        amPageViewContoller?.childScrollViewDidScroll(scrollView)
    }
}

Provide the headerView and headerView height

override func headerViewFor(_ pageController: AquamanPageViewController) -> UIView {
    return HeaderView()
}

override func headerViewHeightFor(_ pageController: AquamanPageViewController) -> CGFloat {
    return headerViewHeight
}

Provide the menuView and menuView height

override func menuViewFor(_ pageController: AquamanPageViewController) -> UIView {
    return menuView
}

override func menuViewHeightFor(_ pageController: AquamanPageViewController) -> CGFloat {
    return menuViewHeight
}

Update menuView's layout when content scroll view did scroll and check state when did end scoll

override func pageController(_ pageController: AquamanPageViewController, contentScrollViewDidScroll scrollView: UIScrollView) {
    menuView.updateLayout(scrollView)
}

override func pageController(_ pageController: AquamanPageViewController,
                             contentScrollViewDidEndScroll scrollView: UIScrollView) {
    menuView.checkState()
}

Examples

Follow these 4 steps to run Example project: Clone Aquaman repository, run the pod install command ,open Aquaman workspace and run the Aquaman-Demo project.

License

Aquaman is released under the MIT license. See LICENSE for details.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK