In the new iOS7 Facebook iPhone app, when the user scrolls up the navigationBar
gradually hides itself to a point where it completely vanishes. Then when the user scrolls down the navigationBar
gradually shows itself.
How would you implement this behavior yourself? I am aware of the following solution but it disappears right away and it isn't tied to the speed of the user's scroll gesture at all.
[navigationController setNavigationBarHidden: YES animated:YES];
I hope this isn't a duplicate as I'm not sure how best to describe the "expanding/contracting" behavior.
HidingNavigationBar a great project that hides the Navigation Bar and the Tab Bar if you want.
https://github.com/tristanhimmelman/HidingNavigationBar
One way that I’ve accomplished this is the following.
Register your view controller to be the
UIScrollViewDelegate
of yourUITableView
for example.From within de
UIScrollViewDelegate
methods you can get the new contentOffset and translate yourUINavigationBar
up or down accordingly.Setting the alpha of the subviews can also be done based on some threshold values and factors you can set and compute.
Hope it helps!
All of these approaches seem overly complicated... So naturally, I built my own:
I found all answers given in Objective-C. This is my answer in Swift 3. This is very generic code and can be used directly. It works with both UIScrollView and UITableView.
The logic of setting alpha to navigation items is copied from @WayneBurkett answer and rewritten in Swift 3.
I have some kind of a quick and dirty solution for that. Haven't made any in-depth testing but here's the idea:
That property will keep all the items in the navbar for my UITableViewController class
In the same UITableViewController class I have:
That's only for ios >= 7, it's ugly I know but a quick way to achieve this. Any comments/suggestions are welcome :)
In addition to Iwburk's answer I added the following to fix the alpha issue on non custom navigation bars and to reset the navigation bar in the viewWillDisappear method: