如何在iOS9中禁用interactivePopGestureRecognizer禁用

时间:2015-12-24 07:35:25

标签: ios objective-c uigesturerecognizer

我需要在我的应用中禁用interactivePopGestureRecognizer,我做了

- (void)viewDidAppear:(BOOL)animated
{

    [super viewDidAppear:animated];

    // Disable iOS 7 back gesture

 if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) 
{

 self.navigationController.interactivePopGestureRecognizer.enabled = NO;

        self.navigationController.interactivePopGestureRecognizer.delegate = self;

    }
}


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

    // Enable iOS 7 back gesture

    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
 {

 self.navigationController.interactivePopGestureRecognizer.enabled = YES;

self.navigationController.interactivePopGestureRecognizer.delegate = nil;

 }
}


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

{

 return NO;
}

适用于'iOS8',我在'iOS9'上有一个问题。

1 个答案:

答案 0 :(得分:1)

如果要禁用interactivePopGestureRecognizer global,可以在创建navigationController后禁用它。

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:rootVC];
nav.interactivePopGestureRecognizer.enabled=NO;