andreamazz /AMScrollingNavbar

Scrollable UINavigationBar that follows the scrolling of a UIScrollView

★ 5,980⑂ 626👁 126⑃ 104● 306▤ 51
SwiftMITCreated 2013-11-08
下载:Release 5.3.0Release-5.3.0 ↓5.3.02019-07-16
+0
日增长
5,980
stars
626
forks
126
watchers
104
prs
306
issues
51
releases

README

!Build status

!Swift 5



A custom UINavigationController that enables the scrolling of the navigation bar alongside the
scrolling of an observed content view  


  
    
  


 Versioning notes

- Version 2.x is written as a subclass of UINavigationController, in Swift.  
- Version 2.0.0 introduced Swift 2.0 syntax.
- Version 3.0.0 introduced Swift 3.0 syntax.
- Version 4.0.0 introduced Swift 4.0 syntax.
- Version 5.1.0 introduced Swift 4.2 syntax.

If you are looking for the category implementation in Objective-C, make sure to checkout version 1.x and prior, although the 2.x is recomended.

 Screenshot


  


 Setup with CocoaPods


pod 'AMScrollingNavbar'

use_frameworks!


 Setup with Carthage


github "andreamazz/AMScrollingNavbar"


 Usage

Make sure to use ScrollingNavigationController instead of the standard UINavigationController. Either set the class of your UINavigationController in your storyboard, or create programmatically a ScrollingNavigationController instance in your code.

Use followScrollView(_: delay:) to start following the scrolling of a scrollable view (e.g.: a UIScrollView or UITableView).
 Swift
swift
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if let navigationController = navigationController as? ScrollingNavigationController {
        navigationController.followScrollView(tableView, delay: 50.0)
    }
}


 Objective-C
objc
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [(ScrollingNavigationController )self.navigationController followScrollView:self.tableView delay:0 scrollSpeedFactor:1 collapseDirection:NavigationBarCollapseDirectionScrollDown followers:nil];
}


Use stopFollowingScrollview() to stop the behaviour. Remember to call this function on disappear:
swift
override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)

    if let navigationController = navigationController as? ScrollingNavigationController {
        navigationController.stopFollowingScrollView()
    }
}


 ScrollingNavigationViewController
To DRY things up you can let your view controller subclass ScrollingNavigationViewController, which provides the base setup implementation. You will just need to call followScrollView(_: delay:):
swift
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if let navigationController = navigationController as? ScrollingNavigationController {
        navigationController.followScrollView(tableView, delay: 50.0)
    }
}


 Followers
To move another view, like a toolbar, alongside the navigation bar you can provide the view or multiple views as the followers parameter. Since you might want to have the follower up or down, you'll have to specify the scroll direction of the view once it starts to follow the navigation bar:
swift
if let navigationController = navigationController as? ScrollingNavigationController {
    navigationController.followScrollView(tableView, delay: 50

Top issues

Latest release

Release 5.3.0 5.3.0 2019-07-16
- Merged 365

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON