Latest 0.0.5
Homepage https://github.com/bawn/Shazam
License MIT
Platforms ios 9.0, requires ARC
Dependencies SnapKit
Authors

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 'Shazam'

Usage

中文文档

First make sure to import the framework:

import Shazam

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 ShazamPageViewController subclass

import Shazam

class PageViewController: ShazamPageViewController {
  // ...
}

Provide the view controllers that will appear embedded into the ShazamPageViewController

override func numberOfViewControllers(in pageController: ShazamPageViewController) -> Int {
    return count
}

override func pageController(_ pageController: ShazamPageViewController, viewControllerAt index: Int) -> (UIViewController & ShazamChildViewController) {
    // ...
    return viewController
}

Every UIViewController that will appear within the ShazamPageViewController should conform to ShazamChildViewController by implementing func shazamChildScrollView() -> UIScrollView

import Shazam
class ChildViewController: UIViewController, ShazamChildViewController {

    @IBOutlet weak var tableView: UITableView!
    func shazamChildScrollView() -> UIScrollView {
        return tableView
    }
    // ...
}

Note: The scrollview of ChildViewController must reserve the height of headerView + menuView at the top. For example, in BatmanViewController in Demo, you need to set the height of Header of collectionView.

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        guard let pageViewContoller = szPageViewContoller else {
            return .zero
        }
        let headerViewHeight = pageViewContoller.headerViewHeightFor(pageViewContoller)
        let menuViewHeight = pageViewContoller.menuViewHeightFor(pageViewContoller)
        return CGSize(width: collectionView.bounds.width, height: headerViewHeight + menuViewHeight)
    }

Provide the headerView and headerView height

override func headerViewFor(_ pageController: ShazamPageViewController) -> UIView & ShazamHeaderView {
    return HeaderView()
}

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

The headerView should conform to ShazamHeaderView by implementing func userInteractionViews() -> [UIView]?

func userInteractionViews() -> [UIView]? {
    return 
}

Provide the menuView and menuView height

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

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

Update menuView’s layout when main scroll view did scroll and check state when did end scoll

override func pageController(_ pageController: ShazamPageViewController, mainScrollViewDidScroll scrollView: UIScrollView) {
    menuView.updateLayout(scrollView)
}

override func pageController(_ pageController: ShazamPageViewController,
                                 mainScrollViewDidEndScroll scrollView: UIScrollView) {
    menuView.checkState()
}

Examples

Follow these 4 steps to run Example project:

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

License

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

Latest podspec

{
    "name": "Shazam",
    "version": "0.0.5",
    "summary": "An easy solution to nested scrolling",
    "homepage": "https://github.com/bawn/Shazam",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "bawn": "[email protected]"
    },
    "swift_versions": "4.2",
    "source": {
        "git": "https://github.com/bawn/Shazam.git",
        "tag": "0.0.5"
    },
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "dependencies": {
        "SnapKit": []
    },
    "source_files": [
        "Shazam/*.swift",
        "Shazam/Shazam.h"
    ],
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This