iOS7 Facebook NavigationBar行为 [英] iOS7 Facebook NavigationBar Behavior

查看:118
本文介绍了iOS7 Facebook NavigationBar行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序或多或少与Facebook / iOS的iOS7应用程序相同的导航概念:

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

一个包含5个选项卡的ContainerViewController,每个选项卡都有一个NavigationController,因为它是rootViewController

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

我现在正在尝试为第一个选项卡的navigationController( - >第一个真实VC)的rootViewController重现Facebook的navigationBar行为,而不仅仅是像NavVC这样的容器)

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).

我可以使用UIScrollView代理方法(scrollViewDidScroll :, scrollViewWillBeginDragging :, scrollViewDidEndDragging:)实现隐藏/显示navigationBar

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

注意:navigationBar的frame.origin.y手动偏移到顶部。我没有使用

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

    [self.navigationController setNavigationBarHidden:]

到目前为止,这真的很顺利。但是我面对2个问题,我不能想到一个解决方案:

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

当我将新的ViewController推到第一个选项卡的导航堆栈时,导航栏保持隐藏。

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

为了解决这个问题,我在推送的ViewController的viewWillAppear:方法中执行此操作:

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];
    }];

此动画与iOS的navigationController推动动画正确匹配。

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

问题:当我导航(弹出推VC)时,导航栏保持可见。

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

我能够解决这个问题在这两个ViewControllers上创建和设置一些属性,但它是一个巨大的混乱,它会变得更加黑客,因为我必须将3或4个不同的ViewController类型推送到此导航堆栈。

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 -.-) :

如何实现类似于Facebook的推/推行为?

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

这是我正在寻找的行为:一个干净的过渡,其中'old'的导航栏保持隐藏,并且显示推送的viewController的栏

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.

注意:屏幕截图是在新的幻灯片从左到右之前采取的,以返回iOS7手势。

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

第二个问题:有没有办法实现全局处理程序,以便在任何viewController中创建此行为,而不必在其中的每一个中实现scrollDelegate逻辑?
我正在考虑一个符合UIScrollView Delegate的委托对象。

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.

感谢您的帮助:)

推荐答案

长篇小说:我建立了自己的定制容器。它提供了在选项卡之间切换的能力,以及在每个选项卡上推送新的ViewControllers。像UINavigationController和UITabBarController之间的混合类似。

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.

这篇关于iOS7 Facebook NavigationBar行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆