UINavigationController交互式Pop手势取消在iOS 8中不起作用?

时间:2015-06-10 06:47:45

标签: ios objective-c iphone

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return NO;
}



- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }

}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        [self.navigationController.interactivePopGestureRecognizer setEnabled:YES];
       self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
}

//使用此代码,但它在iOS 8.3中无效。故事板中是否存在任何问题,或iOS 8中不支持。我很烦恼,请给我一个解决方案。

2 个答案:

答案 0 :(得分:0)

在视图控制器的viewDidLoad方法中添加此2行,您要禁用弹出手势

[self.navigationController.interactivePopGestureRecognizer setEnabled:NO];
self.navigationController.interactivePopGestureRecognizer.delegate = self;

答案 1 :(得分:0)

创建自定义UIBarButtonItem,然后在导航控制器中设置它

self.navigationItem.leftBarButtonItem = customBarItem;

它可能对您有所帮助。