Coder Social home page Coder Social logo

zhutek / aquaman Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bawn/aquaman

0.0 0.0 0.0 2.68 MB

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

Home Page: https://bawn.github.io/#blog

License: MIT License

Swift 96.44% Ruby 1.38% Objective-C 2.17%

aquaman's Introduction

Aquaman

License MIT Pod version Platform info Support Swift 4.2

类似于淘票票首页,抖音、简书个人主页的嵌套滚动库

demo

Requirements

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

Installation

CocoaPods (recommended)

use_frameworks!

pod 'Aquaman'

Usage

English documentation

首先需要导入 Aquaman

import Aquaman

创建 AquamanPageViewController 子类

import Aquaman

class PageViewController: AquamanPageViewController {
  // ...
}

重写以下协议方法以提供 viewController 和相应的数量

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
    }
    // ...
}

重写以下协议方法以提供 headerView 及其高度

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

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

重写以下协议方法以提供 menuView 及其高度

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

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

Aquaman 采用的是 menuView 和主体功能分离的设计,以满足 menuView 有时候需要深度定制的需求,所以 menuView 需要开发者自己实现,当然这里也提供了现成的 menuView 库:Trident

更新 menuView 的布局

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

Examples

Follow these 4 steps to run Example project:

  1. Clone Aquaman repository
  2. Run the pod install command
  3. Open Aquaman workspace
  4. Run the Aquaman-Demo project.

License

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

aquaman's People

Contributors

bawn avatar bugkingk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.