【问题标题】:UINavigationContoller swipe back function not working if its view is added to UIViewContoller如果将其视图添加到 UIViewContoller,则 UINavigationContoller 向后滑动功能不起作用
【发布时间】:2014-05-16 04:32:39
【问题描述】:

我有一个 UIViewController(RootViewController) 设置为 UIWindow 的根视图控制器。 任何视图/视图控制器都会添加到此 RootViewController 子视图中,包括 UINavigationController。

我发现在 iOS7 中 UINavigationController 有一个新的行为,你可以滑回之前的视图控制器。但它不适用于我的情况。

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

所以我的问题是,如果将它添加到 UIViewController,为什么它不能向后滑动??

更新:
原来如果隐藏导航栏,滑动功能会被禁用....

【问题讨论】:

    标签: iphone ios7 uinavigationcontroller swipe


    【解决方案1】:

    这可能与未正确设置视图控制器包含有关。我敢打赌,当您将导航控制器的视图作为子视图添加到UIWindowrootViewController 时,不会在导航控制器的视图控制器上调用-viewDidLoad。有很多关于如何正确设置自定义视图控制器容器的文献,以便在您的视图控制器上触发正确的方法:

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

    此外,如果 Apple 使用转换 API 进行此交互,则这可能与导航控制器的委托未正确连接有关(就像在 UIWindow 上将导航控制器设置为根视图控制器时一样) ,或父视图控制器窃取/隐藏手势。我先看看导航控制器的弹出手势委托,看看它是不是nil

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

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

    // 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.");
    }
    

    【讨论】:

    • 谢谢亚伦!原来我隐藏导航栏使滑动禁用....
    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 2014-09-08
    • 1970-01-01
    相关资源
    最近更新 更多