Giter Site home page Giter Site logo

duk42111 / hidingnavigationbar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tristanhimmelman/hidingnavigationbar

0.0 1.0 0.0 2.18 MB

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

License: MIT License

Ruby 1.69% Swift 96.68% Objective-C 1.64%

hidingnavigationbar's Introduction

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. Include a member variable of type HidingNavigationBarManager in your UIViewController subclass.
  2. 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.
  3. 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:

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)
}

###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" ~> 0.3

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

pod 'HidingNavigationBar', '~> 0.3'

Otherwise, include the following files directly to your project:

  • HidingNavigationBarManager.swift
  • HidingViewController.swift

hidingnavigationbar's People

Contributors

tristanhimmelman avatar felipowsky avatar danieleggert avatar joshwalker avatar

Watchers

duk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.