简体   繁体   中英

iOS 7 disable the swipe back

In iOS apps, there is a default gesture that swipe from the left edge to right the app navigationController will pop view controller.

But is there a way to disable it for specific view?

You can disable it through the public API, See UINavigationController Class Reference

  //iOS7 Customization, swipe to pop gesture
  if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
      navigationController.interactivePopGestureRecognizer.enabled = NO;
  }

Also, you can switch back to previous state when needed

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

its possible but may be a cause for you app rejection

-(void) viewWillAppear:(BOOL)animated 
{
    [super viewWillAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM