License MIT Pod version Platform info Support Swift 4.2
A pure-Swift library for nested display of horizontal and vertical scrolling views.
- iOS 9.0+
- Swift 4.2+
- Xcode 10+
CocoaPods (recommended)
use_frameworks!
pod 'Shazam'
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:
import Shazam class PageViewController: 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) }
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 [button] }
override func menuViewFor(_ pageController: ShazamPageViewController) -> UIView { return menuView } override func menuViewHeightFor(_ pageController: ShazamPageViewController) -> CGFloat { return menuViewHeight }
override func pageController(_ pageController: ShazamPageViewController, mainScrollViewDidScroll scrollView: UIScrollView) { menuView.updateLayout(scrollView) } override func pageController(_ pageController: ShazamPageViewController, mainScrollViewDidEndScroll scrollView: UIScrollView) { menuView.checkState() }
Follow these 4 steps to run Example project:
- Clone Shazam repository
- Run the
pod installcommand - Open Shazam workspace
- Run the Shazam-Demo project.
Shazam is released under the MIT license. See LICENSE for details.