How to hide the navigation bar and toolbar by scrolling down? Swift (e.g. myBridge app)

I want to hide the toolbar and navigation bar when I scroll down the page. And bring it back when I scroll up. How is this possible?

How do I know what drag and drop is? Can I use the pan gesture or is it down by scrolling?

+7
ios swift uinavigationbar uitoolbar
source share
6 answers

Try this simple approach: tested in Swift 3

  func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { if(velocity.y>0) { //Code will work without the animation block.I am using animation block incase if you want to set any delay to it. UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { self.navigationController?.setNavigationBarHidden(true, animated: true) self.navigationController?.setToolbarHidden(true, animated: true) print("Hide") }, completion: nil) } else { UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { self.navigationController?.setNavigationBarHidden(false, animated: true) self.navigationController?.setToolbarHidden(false, animated: true) print("Unhide") }, completion: nil) } } 

Conclusion: Updated

enter image description here

Note. . If you transfer any data from this VC to another VC built into the navigationController . You may need an unhide NavigationBar .

+33
source share

Thanks to everyone how I drove using the AMScrollingController.

https://github.com/andreamazz/AMScrollingNavbar

It is updated for Swift 3.

+5
source share

can you try self.navigationController? .hidesBarsOnTap = true in viewDidAppear, you can also use a hidden combination.

+3
source share

Easy to do this:

 navigationController?.hidesBarsOnSwipe = true 
+3
source share

Here is a very good option for

It is easy to hide and display the navigation of the navigation controller Bar / tabBar as custom scrolls https://github.com/tristanhimmelman/HidingNavigationBar

 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 } ... } 
-one
source share

You can use these lines of code:

 - (void)scrollViewDidScroll: (UIScrollView *)scroll { // UITableView only moves in one direction, y axis CGFloat currentOffset = scroll.contentOffset.y; CGFloat maximumOffset = scroll.contentSize.height - scroll.frame.size.height; // Change 10.0 to adjust the distance from bottom if (maximumOffset - currentOffset <= 10.0) { self.navigationController?.hidden = YES; } else{ self.navigationController?.hidden = NO; } } 
-3
source share

All Articles