• iOS暴力禁用navigationviewcontroller右滑手势和手势的优先级


    1 : UINavigationController push出来的ViewController ,右滑时会pop回到之前的控制器;

         多数的情况下是丰富了用户体验,但是有时候我们不需要这种“体验”,需要禁用右滑返回的手势,关于禁用这个手势iOS中给出了相关方法,但是这些方法不起作用的情况时有发生。

        如果已经尝试过一些方法都不能够禁用右滑的手势,这里还有一个方法 (直接改变右滑手势本身);

       在要禁用右滑手势的ViewController的ViewDidLoad中 改变pan手势的响应事件

    /// 禁用右滑返回手势
        id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
        UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
        [self.view addGestureRecognizer:pan];

       可以将pan手势的响应事件置nil,或者去做别的响应操作;

    2 : 手势的优先级设置

       例如上面的禁用pan手势,如果你想要同时在此时响应swipe事件,这时候是不能响应swipe手势的。

      这时候我们可以设置让swipe的手势的优先级高于pan

    /// 禁用右滑返回手势
        id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
        UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
        [self.view addGestureRecognizer:pan];
        // 添加滑动手势
        /**  轻扫  */
        UISwipeGestureRecognizer * swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
        
        swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
        [self.view addGestureRecognizer:swipeLeft];
        
        UISwipeGestureRecognizer * swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
        swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
        [self.view addGestureRecognizer:swipeRight];
        // 手势的优先级 优先响应swipe手势
        [pan requireGestureRecognizerToFail:swipeLeft];
        [pan requireGestureRecognizerToFail:swipeRight];

    手势优先级方法解释:

    [pan requireGestureRecognizerToFail: swipe];

    如果swipe手势触发失败,这时候再响应pan 手势

  • 相关阅读:
    gets_s()函数的参数太少,strcpy_s():形参和实参 2 的类型不同,等c函数在Visual Studio上出现的问题, get()函数和scanf()读取字符串的区别,栈的随机性
    线性表的顺序存储实现
    汉诺塔问题, 用递归方法求集合中的中位数
    共用体union
    洛谷3384:【模板】树链剖分——题解
    BZOJ4196:[NOI2015]软件包管理器——题解
    BZOJ3140:[HNOI2013]消毒——题解
    BZOJ1059:[ZJOI2007]矩阵游戏——题解
    洛谷4277:萃香的请柬——题解
    BZOJ1854:[SCOI2010]连续攻击游戏——题解
  • 原文地址:https://www.cnblogs.com/code-Officer/p/6771272.html
Copyright © 2020-2023  润新知