简体   繁体   English

iOS7 Facebook NavigationBar行为

[英]iOS7 Facebook NavigationBar Behavior

My App has more or less the same navigation concept as Facebook's / Instagram's iOS7 Apps: 我的应用程序与Facebook的/ Instagram的iOS7应用程序具有或多或少相同的导航概念:

A ContainerViewController with 5 tabs, each of which has a NavigationController as it's rootViewController. 一个带有5个选项卡的ContainerViewController,每个选项卡都有一个NavigationController,因为它是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). 我现在正在尝试为第一个选项卡的navigationController的rootViewController重现Facebook的navigationBar行为( - >第一个'真正的'VC,而不仅仅是像NavVC这样的容器)。

I was able to implement a hiding/showing navigationBar using the UIScrollView Delegate methods (scrollViewDidScroll:, scrollViewWillBeginDragging:, scrollViewDidEndDragging:) 我能够使用UIScrollView Delegate方法实现隐藏/显示navigationBar(scrollViewDidScroll:,scrollViewWillBeginDragging:,scrollViewDidEndDragging :)

Note: The frame.origin.y of the navigationBar is manually offset to the top. 注意:navigationBar的frame.origin.y手动偏移到顶部。 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. 当我将新的ViewController推送到第一个选项卡的导航堆栈时,navigationBar保持隐藏状态。

To solve this problem I do this in the pushed ViewController's viewWillAppear: method : 要解决这个问题,我在推送的ViewController的viewWillAppear:方法中执行此操作:

    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. 此动画与iOS的navigationController推送动画正确匹配。

Problem: when I'm navigating back (popping the pushed VC), the navigationBar stays visible. 问题:当我向后导航(弹出推送的VC)时,navigationBar保持可见。

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. 我能够通过在两个ViewControllers上创建和设置一些属性来解决这个问题,但它是一个巨大的混乱,它将变得更加hacky,因为我将不得不将3或4个不同的ViewController类型推送到此导航堆栈。

My Question (finally -.-) : 我的问题(最后-.-):

How can I achieve a pushing / popping behavior similar to Facebook's ? 如何实现类似Facebook的推/弹行为?

'旧'ViewController的navigationBar保持隐藏,而推送的VC似乎有它的?自己的导航栏?

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. 这是我正在寻找的行为:一个干净的过渡,其中'旧'navigationBar保持隐藏状态,并显示推送的viewController的栏。

Note: the screenshot was taken during the new 'slide from left to right to go back' iOS7 gesture. 注意:屏幕截图是在新的'从左到右滑动以回到'iOS7手势期间拍摄的。

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? 第二个问题:有没有办法实现一个全局处理程序,以便在任何viewController中创建这种行为,而不必在每一个中实现scrollDelegate逻辑? I'm thinking of a delegate object which conforms to UIScrollView Delegate. 我正在考虑一个符合UIScrollView Delegate的委托对象。

Thanks for your help :) 谢谢你的帮助 :)

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. 它提供了在标签之间切换的功能,以及在每个标签上推送新的ViewControllers。 Kind of like a hybrid between UINavigationController and UITabBarController. 有点像UINavigationController和UITabBarController之间的混合。

If you need a more detailed answer on that please let me know. 如果您需要更详细的答案,请告诉我。

I wrote a custom sliding animation transitioning subclass of UINavigationController. 我写了一个自定义滑动动画转换UINavigationController的子类。 It's behavior is similar to Facebook/Instagram. 它的行为类似于Facebook / Instagram。 Previous controller navigationBar stays visible seems OK. 以前的控制器navigationBar保持可见似乎没问题。

Please checkout this CCSlideNavigationTransition . 请查看此CCSlideNavigationTransition Hopes helpful! 希望对你有帮助!

导航栏概念作为Facebook的/ Instagram的iOS7应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM