禁止系统左滑返回手势

- (void)viewDidLoad {

    [super viewDidLoad];

        //禁止左滑返回手势

    id traget = self.navigationController.interactivePopGestureRecognizer.delegate;

    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];

    [self.view addGestureRecognizer:pan];

    }



//或者

-(void)viewWillAppear:(BOOL)animated

{

     [super viewWillAppear:animated];


  //保持系统常亮

    [UIApplication sharedApplication].idleTimerDisabled = YES;


    // 禁用侧滑返回手势

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

         //这里对添加到右滑视图上的所有手势禁用

         for (UIGestureRecognizer *popGesture in self.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {

             popGesture.enabled = NO;

         }

     }


}



-(void)viewWillDisappear:(BOOL)animated

{

    [super viewWillDisappear:animated];

    //自动锁屏(默认)

    [UIApplication sharedApplication].idleTimerDisabled = NO;

    

    // 禁用侧滑返回手势

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

         //这里对添加到右滑视图上的所有手势禁用

         for (UIGestureRecognizer *popGesture in self.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {

             popGesture.enabled = YES;

         }

     }

    }

你可能感兴趣的:(禁止系统左滑返回手势)