zoukankan      html  css  js  c++  java
  • 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 手势

  • 相关阅读:
    oracle 处理找被删掉且提交了事务的数据
    java去除下划线并首字母大写
    假数据仓库-常见数据枚举(日期、月份、周几、星期几,前导零、Excel 列号)
    自然语言处理标注工具——Brat(安装、测试、使用)
    判断当前点击位置在不在某个区域内
    java调用C#程序集
    UE使用EditorUtilityWidget完成简单的编辑器内工具
    CodeForces 230B
    mac中安装启动使用jmeter步骤
    Ubuntu中samba配置过程
  • 原文地址:https://www.cnblogs.com/code-Officer/p/6771272.html
Copyright © 2011-2022 走看看