Search code examples
iosuiscrollviewuigesturerecognizerinteractivepopgesture

Disable scrolling when interactivePopGestureRecognizer transition is taking place


I have implemented the interactivePopGestureRecognizer. It transitions to the previous page. But the problem is that when the transition takes place, if there is a UIScrollView in the current view controller, it starts scrolling. Is there some way to prevent it?

I have added the gesture in my RootViewcontroller:

   self.appNavController = [[UINavigationController alloc] initWithRootViewController:controller];
    self.appNavController.interactivePopGestureRecognizer.enabled = YES;
    self.appNavController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
    [self.appNavController setNavigationBarHidden:YES];

I call this in:

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    APP_DELEGATE.rootViewController.appNavController.interactivePopGestureRecognizer.enabled = NO;

}

-(void)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];

    APP_DELEGATE.rootViewController.appNavController.interactivePopGestureRecognizer.enabled = YES;

}

Solution

  • I found the solution. In the view controller which is being swiped i added the following:

    - (void)viewDidAppear:(BOOL)animated{
        [super viewDidAppear:animated];
    
        self.scrollView.scrollEnabled = YES;
    }
    
    - (void)viewWillDisappear:(BOOL)animated{
        [super viewWillDisappear:animated];
    
        self.scrollView.scrollEnabled = NO;
    }
    

    It worked like a charm.