2

How can i scroll my UINavigationBar according to a UITableView scroll,i mean:

  • When the user scrolls the UITableView down,the UINavigationBar should scroll with the UITableView and disappear;
  • When the user scrolls the UITableView up,the UINavigationBar should stay fixed on the top of the view.

I want a similar effect to this question but instead of a UISearchBar i need to do the same effect with a UINavigationBar,i've already tried the code from the link.Please any piece of code or source code will be appreciated.

Thanks in advance.

Community
  • 1
  • 1
Mateus
  • 2,640
  • 5
  • 44
  • 62
  • Is the `UINavigationBar` provided by a `UINavigationController`? If so the docs for [UINavigationController](http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html) state you must never change the navigationBars frame or bounds – Paul.s Oct 21 '12 at 21:54
  • It is a new UINavigationBar.The problem is how?I've already tried to make the UINavigationBar frame static when the user scroll the UITableView but it didn't worked. – Mateus Oct 21 '12 at 23:12
  • 1
    To make it stay still implement `scrollViewDidScroll:` on the object acting as the tableViewDelegate and then change the frame of the navigationBar in that – Paul.s Oct 21 '12 at 23:16
  • I did not use an navigation bar but added a uiview instead. I also used scrollViewDidScroll delegate but my approach was a bit different. You might want to check the source code below https://www.dropbox.com/s/b2c0zw6yvchaia5/FailedBanks.zip?dl=0 – Deepak Thakur Jan 03 '16 at 17:34

3 Answers3

2

You can checkout the code for this library. It behaves a little differently (it mimicks the Chrome ios7 app), but you can easily rework the navbar handling to fit your needs.

andreamazz
  • 4,256
  • 1
  • 20
  • 36
1

I found an interesting post that might help. http://horseshoe7.wordpress.com/2012/05/18/uinavigationbar-that-scrolls-away/

Tatarasanu Victor
  • 656
  • 1
  • 7
  • 19
0

I would do this by hiding the navigationBar of the ViewController and adding a fake UINavigationBar into the Header of the first section of the tableView.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • I've already thought on that but how can i make the UINavigationBar static when the user is in the top of the UITableView and still scrolling up?Check the images from the link that i provided. – Mateus Oct 21 '12 at 23:11
  • Hmm... I see your point. Possibly, instead of hiding the navigation bar you could access the scrollView delegate methods of UITableViewController and sue the offset of the scroll view to adjust the frame (or centre point) of the UINavigationBar. That way you can move it up if necessary but not move it down below its normal position. I've never tried this though. – Fogmeister Oct 22 '12 at 06:51