美文网首页
禁止系统左滑返回手势

禁止系统左滑返回手势

作者: 野咪咕 | 来源:发表于2021-09-03 16:00 被阅读0次

    - (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;

             }

         }

        }

    相关文章

      网友评论

          本文标题:禁止系统左滑返回手势

          本文链接:https://www.haomeiwen.com/subject/jzekwltx.html