{"id":20704720,"url":"https://github.com/bawn/shazam","last_synced_at":"2025-04-23T01:28:18.051Z","repository":{"id":56922101,"uuid":"173702152","full_name":"bawn/Shazam","owner":"bawn","description":"A pure-Swift library for nested display of horizontal and vertical scrolling views","archived":false,"fork":false,"pushed_at":"2022-04-20T02:10:40.000Z","size":6988,"stargazers_count":92,"open_issues_count":1,"forks_count":20,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T03:18:36.352Z","etag":null,"topics":["ios","menuview","nestedscrollview","page","pageviewcontroller","scrollview","swift"],"latest_commit_sha":null,"homepage":"https://bawn.github.io/#blog","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bawn.png","metadata":{"files":{"readme":"README-CHINESE.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-04T08:14:55.000Z","updated_at":"2024-12-31T12:17:00.000Z","dependencies_parsed_at":"2022-08-21T04:50:14.415Z","dependency_job_id":null,"html_url":"https://github.com/bawn/Shazam","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bawn%2FShazam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bawn%2FShazam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bawn%2FShazam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bawn%2FShazam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bawn","download_url":"https://codeload.github.com/bawn/Shazam/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250351533,"owners_count":21416338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","menuview","nestedscrollview","page","pageviewcontroller","scrollview","swift"],"created_at":"2024-11-17T01:14:30.281Z","updated_at":"2025-04-23T01:28:18.033Z","avatar_url":"https://github.com/bawn.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shazam\n\n![License MIT](https://img.shields.io/dub/l/vibe-d.svg)\n![Pod version](http://img.shields.io/cocoapods/v/Shazam.svg?style=flat)\n![Platform info](http://img.shields.io/cocoapods/p/LCNetwork.svg?style=flat)\n[![Support](https://img.shields.io/badge/support-iOS9.0+-blue.svg?style=flat)](https://www.apple.com/nl/ios/)\n[![Swift 4.2](https://camo.githubusercontent.com/cc157628e33009bbb18f6e476955a0f641f407d9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53776966742d342e322d6f72616e67652e7376673f7374796c653d666c6174)](https://developer.apple.com/swift/)\n\nA pure-Swift library for nested display of horizontal and vertical scrolling views.\n\n![demo](./demo.gif)\n\n## Requirements\n\n- iOS 9.0+ \n- Swift 4.2+\n- Xcode 10+\n\n\n\n## Installation\n\n#### [CocoaPods](http://cocoapods.org/) (recommended)\n\n```\nuse_frameworks!\n\npod 'Shazam'\n```\n\n## Usage\n\n首先需要导入 Shazam\n\n```\nimport Shazam\n```\n\n\n\n#### 创建 ShazamPageViewController 子类\n\n```swift\nimport Shazam\n\nclass PageViewController: ShazamPageViewController {\n  // ...\n}\n```\n\n#### 重写协议方法以提供 viewController 和相应的数量\n\n```swift\noverride func numberOfViewControllers(in pageController: ShazamPageViewController) -\u003e Int {\n    return count\n}\n    \noverride func pageController(_ pageController: ShazamPageViewController, viewControllerAt index: Int) -\u003e (UIViewController \u0026 ShazamChildViewController) {\n    // ...\n    return viewController\n}\n    \n```\n\n所提供的 viewController 必须都遵守 `ShazamChildViewController` 协议，并实现 `func shazamChildScrollView() -\u003e UIScrollView` 方法\n\n```swift\nimport Shazam\nclass ChildViewController: UIViewController, ShazamChildViewController {\n\n    @IBOutlet weak var tableView: UITableView!\n    func shazamChildScrollView() -\u003e UIScrollView {\n        return tableView\n    }\n    // ...\n}\n```\n\n**注意：ChildViewController 的 scrollview 必须在顶部预留 headerView + menuView 的高度，比如在 Demo 里的 BatmanViewController，就需要设置 collectionView 的 Header 高度**\n\n```swift\nfunc collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -\u003e CGSize {\n        guard let pageViewContoller = szPageViewContoller else {\n            return .zero\n        }\n        let headerViewHeight = pageViewContoller.headerViewHeightFor(pageViewContoller)\n        let menuViewHeight = pageViewContoller.menuViewHeightFor(pageViewContoller)\n        return CGSize(width: collectionView.bounds.width, height: headerViewHeight + menuViewHeight)\n    }\n```\n\n\n\n#### 重写协议方法以提供 headerView 及其高度\n\n```swift\noverride func headerViewFor(_ pageController: ShazamPageViewController) -\u003e UIView {\n    return HeaderView()\n}\n\noverride func headerViewHeightFor(_ pageController: ShazamPageViewController) -\u003e CGFloat {\n    return headerViewHeight\n}\n```\n\n而且 HeaderView 必须遵守 `ShazamHeaderView` 协议，并实现 `func userInteractionViews() -\u003e [UIView]?` 方法 \n\n```swift\nfunc userInteractionViews() -\u003e [UIView]? {\n    return [button]\n}\n```\n\n#### 重写协议方法以提供 menuView 及其高度\n\n```swift\noverride func menuViewFor(_ pageController: ShazamPageViewController) -\u003e UIView {\n    return menuView\n}\n\noverride func menuViewHeightFor(_ pageController: ShazamPageViewController) -\u003e CGFloat {\n    return menuViewHeight\n}\n```\n\n考虑到有时候 menuView 需要高度的定制性，所以设计成由开发者自行提供（demo 中有 menuView 的实现方法）。\n\n#### 更新 menuView 的布局\n\n```swift\noverride func pageController(_ pageController: ShazamPageViewController, mainScrollViewDidScroll scrollView: UIScrollView) {\n    menuView.updateLayout(scrollView)\n}\n\noverride func pageController(_ pageController: ShazamPageViewController,\n                                mainScrollViewDidEndScroll scrollView: UIScrollView) {\n    menuView.checkState()\n}\n```\n\n包括在内容的滚动的时候和停止滚动的时候，具体可参考 demo\n\n## Examples\n\nFollow these 4 steps to run Example project: \n\n1. Clone Shazam repository\n2. Run the `pod install` Shazam \n3. Open Shazam workspace \n4. Run the Shazam-Demo project.\n\n### License\n\nShazam is released under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbawn%2Fshazam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbawn%2Fshazam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbawn%2Fshazam/lists"}