iOS7 Facebook NavigationBar Behavior

六眼飞鱼酱① 提交于 2020-01-02 05:34:09

问题


My App has more or less the same navigation concept as Facebook's / Instagram's iOS7 Apps:

A ContainerViewController with 5 tabs, each of which has a NavigationController as it's rootViewController.

I'm now trying to reproduce Facebook's navigationBar behavior for the rootViewController of the first tab's navigationController (-> the first 'real' VC, not just a container like NavVC).

I was able to implement a hiding/showing navigationBar using the UIScrollView Delegate methods (scrollViewDidScroll:, scrollViewWillBeginDragging:, scrollViewDidEndDragging:)

Note: The frame.origin.y of the navigationBar is manually offset to the top. I'm NOT using

    [self.navigationController setNavigationBarHidden:]

It's really smooth so far. But I'm facing 2 problems i can't think of a solution for:

When I'm pushing a new ViewController onto the first tab's navigation stack, the navigationBar stays hidden.

To solve this problem I do this in the pushed ViewController's viewWillAppear: method :

    CGRect navBarFrame = self.navigationController.navigationBar.frame;
    navBarFrame.origin.y = 20.0;
    [UIView animateWithDuration:0.3 animations:^{
        [self.navigationController.navigationBar setFrame:navBarFrame];
    }];

This animation is matched properly to the navigationController push animation by iOS.

Problem: when I'm navigating back (popping the pushed VC), the navigationBar stays visible.

I was able to solve this problem by creating and setting some properties on both ViewControllers but it is a huge mess and it will get even more hacky, because I'll have to push 3 or 4 different ViewController types onto this navigation stack.

My Question (finally -.-) :

How can I achieve a pushing / popping behavior similar to Facebook's ?

This is the behavior I'm looking for: a clean transition, where the 'old' navigationBar stays hidden and the pushed viewController's bar is shown.

Note: the screenshot was taken during the new 'slide from left to right to go back' iOS7 gesture.

The second question: Is there a way to implement a global handler in order to create this behavior in any viewController without having to implement the scrollDelegate logic in every single one of them? I'm thinking of a delegate object which conforms to UIScrollView Delegate.

Thanks for your help :)


回答1:


Long story short: I built my own custom container for that. It provides the ability to switch between tabs, as well as pushing new ViewControllers on each tab. Kind of like a hybrid between UINavigationController and UITabBarController.

If you need a more detailed answer on that please let me know.




回答2:


I wrote a custom sliding animation transitioning subclass of UINavigationController. It's behavior is similar to Facebook/Instagram. Previous controller navigationBar stays visible seems OK.

Please checkout this CCSlideNavigationTransition. Hopes helpful!



来源:https://stackoverflow.com/questions/20641464/ios7-facebook-navigationbar-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!