在iOS7中,UINavigationController的异常弹出动作与边缘滑动 [英] In iOS7, abnormal popping action of UINavigationController with edge swiping

查看:236
本文介绍了在iOS7中,UINavigationController的异常弹出动作与边缘滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UINavigationController中使用边缘滑动弹出视图控制器(VC)时发现了一个看起来像iOS7的bug。

I found one that looks like iOS7 bug while popping view controllers(VCs) in UINavigationController with edge swiping.

我设置如下VC层次结构:

I set up as following VC hierarchy:

UINagivationController
  |
  --- UIVewControllerR (root)
            |
            --- UIViewControllerA
                      |
                      --- UIViewControllerB  

我试图通过边缘滑动弹出UIViewControllerB并弹出UIViewControllerA不断。它运作良好。但是,如果第一次滑动操作被取消然后重试弹出它,我发现了一个错误。在弹出UIViewControllerA后,我发现UIViewControllerA的导航栏项仍然显示,尽管弹出UIViewControllerA。

I tried to pop UIViewControllerB up by edge swiping and popped UIViewControllerA up continuously. It worked well. But, If first swiping action is canceled then retry to pop it up, a bug I found comes out. After popping UIViewControllerA, I found that UIViewControllerA's navigation bar items were still showed despite popping UIViewControllerA up.

简而言之,UIViewControllerR显示了UIViewControllerA的导航栏项目。

In short, UIViewControllerR was showed with items of UIViewControllerA's navigation bar items.

没有可能影响UINavigationController转换的代码。

这是iOS7上的错误吗?

There is no code that is likely to affect transition of UINavigationController.
Is it a bug on iOS7?

推荐答案

我找到了解决这个问题的方法。

I found a solution to this problem.

我做的是在我的UINagivationController类中,设置了一个BOOL属性名为

What I did was in my UINagivationController class, set a BOOL property called

@property (nonatomic, assign) BOOL interactivePopGestureComplete;

然后在UINagivationController的初始化

and then in init of that UINagivationController

self.interactivePopGestureComplete = YES;
    if([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
        [self.interactivePopGestureRecognizer addTarget:self action:@selector(defaultGestureAction:)];

以及这样的操作方法:

- (void)defaultGestureAction:(UIGestureRecognizer *)sender
{
    if(sender.state == UIGestureRecognizerStateBegan || sender.state == UIGestureRecognizerStateChanged)
        self.interactivePopGestureComplete = NO;
    else
        self.interactivePopGestureComplete = YES;
}

和viewWillAppear:或viewWillLayoutSubviews :(在viewControllers中出现此问题) ),无论在这两种方法中你更新navigationBarButtons和navigationBar,只需检查

and in viewWillAppear: or viewWillLayoutSubviews: (in the viewControllers where there is this problem), wherever in these two methods you are updating the navigationBarButtons and the navigationBar, just check if

// Lets say our UINagivationController class name is NavigationCon
NavigationCon *navCon = (NavigationCon *)self.navigationController;
if(navCon.interactivePopGestureComplete)
{
    // only then update navigationBar
} 

这篇关于在iOS7中,UINavigationController的异常弹出动作与边缘滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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