Easily hide and show a view controller's navigation bar (and tab bar) as a user scrolls

Overview

HidingNavigationBar

Carthage compatible CocoaPods

An easy to use library (written in Swift) that manages hiding and showing a navigation bar as a user scrolls.

Features

HidingNavigationBar supports hiding/showing of the following view elements:

  • UINavigationBar
  • UINavigationBar and an extension UIView
  • UINavigationBar and a UIToolbar
  • UINavigationBar and a UITabBar

UINavigationBar

Screenshot

UINavigationBar and an extension UIView

Screenshot

UINavigationBar and a UIToolbar

Screenshot

A UINavigationBar and a UITabBar

Screenshot

Usage

  1. Import HidingNavigationBar
  2. Include a member variable of type HidingNavigationBarManager in your UIViewController subclass.
  3. Initialize the variable in viewDidLoad function, passing in the UIViewController instance and the UIScrollView instance that will control the hiding/showing of the navigation bar.
  4. Relay the following UIViewController lifecycle functions to the HidingNavigationBarManager variable:
override func viewWillAppear(animated: Bool)
override func viewWillDisappear(animated: Bool)
override func viewDidLayoutSubviews() //Only necessary when adding the extension view

And finally relay the following UIScrollViewDelegate function:

func scrollViewShouldScrollToTop(scrollView: UIScrollView) -> Bool

Below is an example of how your UIViewController subclass should look:

import HidingNavigationBar

class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

	var hidingNavBarManager: HidingNavigationBarManager?
	@IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

		hidingNavBarManager = HidingNavigationBarManager(viewController: self, scrollView: tableView)
    }

	override func viewWillAppear(animated: Bool) {
		super.viewWillAppear(animated)

		hidingNavBarManager?.viewWillAppear(animated)
	}

	override func viewDidLayoutSubviews() {
		super.viewDidLayoutSubviews()

		hidingNavBarManager?.viewDidLayoutSubviews()
	}

	override func viewWillDisappear(animated: Bool) {
		super.viewWillDisappear(animated)

		hidingNavBarManager?.viewWillDisappear(animated)
	}

	//// TableView datasoure and delegate

	func scrollViewShouldScrollToTop(scrollView: UIScrollView) -> Bool {
		hidingNavBarManager?.shouldScrollToTop()

		return true
	}

	...
}

Note: HidingNavigationBar only works with UINavigationBars that have translucent set to true.

Customization

Add an extension view to the UINavigationBar

let extensionView = // load your a UIView to use as an extension
hidingNavBarManager?.addExtensionView(extensionView)

Hide and show a UITabBar or UIToolbar

if let tabBar = navigationController?.tabBarController?.tabBar {
	hidingNavBarManager?.manageBottomBar(tabBar)
}

Hide/Show/Do Nothing when App is Foregrounded

	hidingNavBarManager?.onForegroundAction = .Default	//Do nothing, state of bars will remain the same as when backgrounded
	hidingNavBarManager?.onForegroundAction = .Hide		//Always hide on foreground
	hidingNavBarManager?.onForegroundAction = .Show 	//Always show on foreground

Expansion Resistance

When the navigation bar is hidden, you can some 'resitance' which adds a delay before the navigation bar starts to expand when scrolling. The resistance value is the distance that the user needs to scroll before the navigation bar starts to expand.

hidingNavBarManager?.expansionResistance = 150

UIRefreshControl

If you are using a UIRefreshControl with your scroll view, it is important to let the HidingNavigationBarManager know about it:

hidingNavBarManager?.refreshControl = refreshControl

Installation

If your using Carthage, add the following line to your Cartfile:

github "tristanhimmelman/HidingNavigationBar" ~> 2.0

(for Swift 3, use github "tristanhimmelman/HidingNavigationBar" ~> 1.0 instead)

If you are using CocoaPods, add the following line to your Podfile:

pod 'HidingNavigationBar', '~> 2.0'

(for Swift 3, use pod 'HidingNavigationBar', '~> 1.0' instead)

Otherwise, include the following files directly to your project:

  • HidingNavigationBarManager.swift
  • HidingViewController.swift
Comments
  • Updated for iOS 11.

    Updated for iOS 11.

    The structure of UINavigationBar has changed in iOS 11. This meant that navigation bar was not fading out and was clashing with the status bar. I modified the code to recursively apply the new alpha value. The change should be benign on older OS versions.

    This PR may solve issue #67.

    opened by iosdevzone 7
  • v0.3.0 does expose the `onForegroundAction` option

    v0.3.0 does expose the `onForegroundAction` option

    Hello, I installed v0.3.0 and it does not have the onForegroundAction option. the source code doesn't have the line:

        //Options
        public var onForegroundAction = HidingNavigationForegroundAction.Default
    

    Could it be the wrong version being pushed?

    pod install log:

    $ pod install
    Updating local specs repositories
    
    CocoaPods 1.1.0.beta.1 is available.
    To update use: `gem install cocoapods --pre`
    [!] This is a test version we'd love you to try.
    
    For more information see http://blog.cocoapods.org
    and the CHANGELOG for this version http://git.io/BaH8pQ.
    
    Analyzing dependencies
    Downloading dependencies
    ...
    Installing HidingNavigationBar (0.3.0)
    ...
    Generating Pods project
    Integrating client project
    Sending stats
    Pod installation complete! There are 31 dependencies from the Podfile and 36 total pods installed.
    
    
    opened by simoami 5
  • HidingNavigationBar Integration Issue

    HidingNavigationBar Integration Issue

    I have added the the library through CocoaPods and after that I have tried to add the variable of HidingNavigationBarManager but I'm getting this issue

    Use of undeclalead type 'HidingNavigationBarManager'

    Should I import something else?

    Thanks.

    opened by LuaiKalkatawi 2
  • New hidingNavigationBarManager property in UIViewController

    New hidingNavigationBarManager property in UIViewController

    • Added hidingNavigationBarManager property in UIViewController by extension
    • Swizzled viewWillAppear, viewDidLayoutSubviews and viewWillDisappear to use the new hidingNavigationBarManager property
    • Added new example: Hiding Nav Bar (Internal)

    hidingNavigationBarManager property isn't required. Once attributed it isn't necessary to implement viewWillAppear, viewDidLayoutSubviews or viewWillDisappear.

    It's still necessary to implement scrollViewShouldScrollToTop in order to enable scroll to top.

    opened by felipowsky 2
  • Hiding status bar expands navigation bar

    Hiding status bar expands navigation bar

    How to reproduce in the demo project: Add this to HidingNavViewController.swift:

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { UIApplication.sharedApplication() .setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Slide) }

    and then go to Hiding Nav Bar, scroll down a bit so that the bar collapses, and tap on a row. The bar will then expand but without resetting the subviews' alpha values.

    Is this a quick fix? I'm not very experienced in Swift. Thank you!

    opened by VrasidasP 2
  • Upgrade to Swift 4

    Upgrade to Swift 4

    After merging this PR, please create a 2.0.0 tag:

    cd HidingNavigationBar/
    git checkout master
    git pull origin master
    git tag 2.0.0
    git push origin 2.0.0
    

    Then, send an update to CocoaPods, that way we can just run pod update HidingNavigationBar and get all of the Swift 4 goodies:

    pod trunk push
    

    Thanks!

    opened by jeffaburt 1
  • shouldUpdateScrollViewInsets method

    shouldUpdateScrollViewInsets method

    Added: func hidingNavigationBarManagerShouldUpdateScrollViewInsets(_ manager: HidingNavigationBarManager, insets: UIEdgeInsets) -> Bool

    This is method for better customization. I need this to configure hiding manager change autolayout config instead of scrollview insets in my application.

    opened by rsrbk 1
  • Set my Xcode target to 8.0, but still can't install from cocopods

    Set my Xcode target to 8.0, but still can't install from cocopods

    Analyzing dependencies [!] Unable to satisfy the following requirements:

    • HidingNavigationBar required by Podfile

    Specs satisfying the HidingNavigationBar dependency were found, but they required a higher minimum deployment target.

    opened by alexliubj 1
  • Strong Reference Cycle

    Strong Reference Cycle

    Calling HidingNavigationBarManager(viewController: self, scrollView: scrollView) on the view controller does not allow that view controller to deallocate when needed.

    opened by zgosalvez 1
  • Fix navigation bar and extension view hiding suddenly

    Fix navigation bar and extension view hiding suddenly

    Right after a small pan gesture that wasn't enough to hide the navigation bar and the extension view, if pan gesture is fired again the navigation and the extension hide suddenly.

    I noticed this bug happening more frequently with an extension view but I think it's possible to simulate it in other scenarios.

    Here an example: nav_bug

    Fixed it by resetting the previousYOffset at handleScrollingEnded to NaN.

    Here's the expected result: nav_fix

    opened by felipowsky 1
  • all what we have to do is the following instead of using a pod

    all what we have to do is the following instead of using a pod

    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        let translation = scrollView.panGestureRecognizer.translation(in: scrollView.superview)
        if(translation.y > 0){
            self.navigationController?.setNavigationBarHidden(false, animated: true)
        }else{
            self.navigationController?.setNavigationBarHidden(true, animated: true)
        }
        
    }
    
    opened by AymanOmara 1
  • 'titleForHeaderInSection' and 'sectionIndexTitle'  is disappeared on Grouped Style UITableView.

    'titleForHeaderInSection' and 'sectionIndexTitle' is disappeared on Grouped Style UITableView.

    Title Header of Table section is gone when I scroll tableView upward. Could I turn it back to the sticky header like the pure UITableView works? Section Index Title Bar problem is same. Thanks for reading my issue.

    opened by dotnetguy83 0
  • Nav title flickers when hiding

    Nav title flickers when hiding

    Repro steps:

    Set the title of the nav bar, and scroll up slowly. The title flickers.

    Nav bar sets the alpha of the bar whenever the nav bar size changes.

    opened by CamZhou 2
  • Problem in the extension View

    Problem in the extension View

    Hello this is a great library. I have used this on my project. In my view controller i have a collectionView and above the collectionView there is the extensionView and above that there is navigationBar, in the collectionView there is textview in every cell. now when i am trying to show the keyboard, and want to hide the keyboard the extensionView is coming down and there is seeing a black space between the extensionView and Navigation bar. Some one please help me in this matter.

    opened by goribchat 1
Owner
Tristan Himmelman
Tristan Himmelman
iOS UI library to show and hide an extension to your UINavigationBar

ADNavigationBarExtension is a UI library written in Swift. It allows you to show and hide an extension to your UINavigationBar Features Use Extensible

FABERNOVEL 58 Aug 29, 2022
An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation.

swiftui-navigation-stack An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations

Matteo 753 Jan 2, 2023
Change SwiftUI Navigation Bar Color for different View

SwiftUINavigationBarColor Change SwiftUI NavigationBar background color per screen. Usage For NavigationBarColor to work, you have to set the Navigati

Hai Feng Kao 18 Jul 15, 2022
Simple and integrated way to customize navigation bar experience on iOS app.

NavKit Simple and integrated way to customize navigation bar experience on iOS app. It should save our time that we usually use to make abstraction of

Wilbert Liu 37 Dec 7, 2022
Simple custom navigation bar by swift

YoNavBarView Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation YoNav

null 1 Nov 23, 2021
Replicating the 'clear' navigation bar style of the iOS 12 Apple TV app.

TONavigationBar TONavigationBar is an open-source subclass of UINavigationBar that adds the ability to set the background content of the navigation ba

Tim Oliver 247 Dec 7, 2022
An iOS view-controller navigation management. No inherit, using one line code to integrate.

KGNavigationBar Example An iOS view-controller navigation management. No inherit, using one line code to integrate. 一个 iOS 控制器导航管理库. 无需继承, 一行代码即可实现集成。

VanJay 5 Sep 6, 2021
FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator

FlowStacks allow you to manage complex SwiftUI navigation and presentation flows with a single piece of state. This makes it easy to hoist that state into a high-level coordinator view. Using this pattern, you can write isolated views that have zero knowledge of their context within the navigation flow of an app.

John Patrick Morgan 471 Jan 3, 2023
A wrapper for NavigationView and NavigationLink that makes programmatic navigation a little friendlier.

NavigatorKit A wrapper for NavigationView and NavigationLink that makes programmatic navigation a little friendlier. NavigatorKit is an opinionated wr

Gyuri Grell 2 Jun 16, 2022
Tools for making SwiftUI navigation simpler, more ergonomic and more precise.

SwiftUI Navigation Tools for making SwiftUI navigation simpler, more ergonomic and more precise. Motivation Tools Navigation overloads Navigation view

Point-Free 1.1k Jan 1, 2023
SwiftUINavigator: a lightweight, flexible, and super easy library which makes SwiftUI navigation a trivial task

The logo is contributed with ❤️ by Mahmoud Hussein SwiftUINavigator is a lightwe

OpenBytes 22 Dec 21, 2022
Models UI navigation patterns using TCA

Composable Navigation The Composable Navigation is a Swift Package that builds on top of The Composable Architecture (TCA, for short). It models UI na

Michael Heinzl 41 Dec 14, 2022
sRouting - The lightweight navigation framework for SwiftUI.

sRouting The lightweight navigation framework for SwiftUI. Overview sRouting using the native navigation mechanism in SwiftUI. It's easy to handle nav

Shiro 8 Aug 15, 2022
🧭 SwiftUI navigation done right

?? NavigationKit NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. ?? Installation ?? Swift Package Manager Usi

Alex Nagy 152 Dec 27, 2022
Navigation helpers for SwiftUI applications build with ComposableArchitecture

Swift Composable Presentation ?? Description Navigation helpers for SwiftUI applications build with ComposableArchitecture. More info about the concep

Dariusz Rybicki 52 Dec 14, 2022
Powerful navigation in the Composable Architecture via the coordinator pattern

TCACoordinators The coordinator pattern in the Composable Architecture TCACoordinators brings a flexible approach to navigation in SwiftUI using the C

John Patrick Morgan 231 Jan 7, 2023
Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

Launch Navigator Cordova/Phonegap Plugin Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

null 0 Oct 25, 2021
Make SwiftUI Navigation be easy

VNavigator VNavigator is a clean and easy-to-use navigation in SwiftUI base on UINavigationController in UIKit Installation From CocoaPods CocoaPods i

Vu Vuong 10 Dec 6, 2022
SwiftUINavigation provides UIKit-like navigation in SwiftUI

SwiftUINavigation About SwiftUINavigation provides UIKit-like navigation in Swif

Bhimsen Padalkar 1 Mar 28, 2022