如果将其视图添加到UIViewContoller,则UINavigationContoller向后滑动功能不起作用 [英] UINavigationContoller swipe back function not working if its view is added to UIViewContoller

查看:92
本文介绍了如果将其视图添加到UIViewContoller,则UINavigationContoller向后滑动功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIViewController(RootViewController)设置为UIWindow的根视图控制器。
任意视图/视图控制器被加入到这一RootViewController的子视图包括一个UINavigationController。

I have a UIViewController(RootViewController) set as the root view controller of the UIWindow. Any view / view controller is added to this RootViewController subview including a UINavigationController.

我发现有在iOS7一个新行为的UINavigationController可以滑动回到上一个视图控制器。但它并不适用于我的情况。

I found that there is a new behaviour in iOS7 for UINavigationController that you can swipe back to the previous view controller. But it doesn't not work for my case.

如果我将UINavigationController设置为UIWindow的根视图控制器。它有效。

If I set the UINavigationController as the root view controller of the UIWindow. It works.

所以我的问题是为什么如果它被添加到UIViewController中它不能刷回来?

So my questions is why can't it swipe back if it is added to a UIViewController??

已更新:

事实证明,如果导航栏被隐藏,则滑动功能将被禁用....

Updated:
It turns out that if the navigation bar is hidden, the swipe function will be disabled....

推荐答案

这可能与未正确设置视图控制器包含有关。我打赌当你将导航控制器的视图作为子视图添加到 UIWindow -viewDidLoad c>的 rootViewController 。关于如何正确设置自定义视图控制器包含,以便正确的方法触发视图控制器,有很多文献:

This probably has something to do with not properly setting up view controller containment. I bet -viewDidLoad is not being called on your navigation controller's view controllers when you add the navigation controller's view as a subview to UIWindow's rootViewController. There's a good bit of literature out there on how to properly set up a custom view controller containment such that the right methods fire on your view controllers:

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/ CreatingCustomContainerViewControllers.html

此外,如果Apple使用转换API进行此交互,则可能与导航控制器的委托未被挂钩有关正确启动(就像导航控制器在UIWindow上设置为根视图控制器时那样),或者父视图控制器窃取/隐藏手势。我首先看一下导航控制器的pop手势委托,看看它是否 nil

Also, if Apple used the transition API for this interaction its possible that this has something to do with either the navigation controller's delegate not being hooked up properly (as it would when navigation controllers are set as root view controllers' on UIWindow), or the parent view controller stealing/hiding the gesture. I would first take a look at the navigation controller's pop gesture delegate and see if it not nil:

NSLog(@"%@", self.navigationController.interactivePopGestureRecognizer.delegate);

如果它不是 nil 那么我会检查导航控制器上的手势识别器可以正常触发:

If it's not nil then I would check that a gesture recognizer on the navigation controller can fire normally:

// In the navigation controller's root view controller, try this:
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move)];
[panRecognizer setMaximumNumberOfTouches:1];
[self.view addGestureRecognizer:panRecognizer];


// Then test to see if its working:
- (void)move {
    NSLog(@"Hello world.");
}

这篇关于如果将其视图添加到UIViewContoller,则UINavigationContoller向后滑动功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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