• iOS自定义全屏返回与tableView左划删除手势冲突解决


    当自定义一个navigationController实现全屏右划返回时, 使用起来是不是很爽, 代码如下:

    - (void)viewDidLoad {
    
        [super viewDidLoad];
    
        UIGestureRecognizer  *gester = self.interactivePopGestureRecognizer;
    UIPanGestureRecognizer
    *panGesTer = [[UIPanGestureRecognizer alloc] initWithTarget:gester.delegate action:NSSelectorFromString(@"handleNavigationTransition:")];
    [gester.view addGestureRecognizer:panGesTer];
    gester.delaysTouchesBegan
    = YES;
    panGesTer.
    delegate = self; }

    -(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{

        if (self.childViewControllers.count == 1 ) {

            return NO;

        }

        return YES;

    }

     

            然鹅, 当你在tableView中打开左划编辑功能时发现死活也左划不了, 肿么肥四呢, 是打开姿势不对吗, MGD!  还是手势冲突呢?

            好吧, 打个断点试试! 断点后发现进不来tableView的编辑方法,  进到了自定义的navigationController的gestureRecognizerShouldBegin方法, 原来是被拦截了.  那来判断一下是左划还是右划吧, 如果左划的话就不拦截, 交给tableView去响应! 代码如下:

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
        if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
            
            if (self.childViewControllers.count == 1 ) {
                return NO;
            }
            
            if (self.interactivePopGestureRecognizer &&
                [[self.interactivePopGestureRecognizer.view gestureRecognizers] containsObject:gestureRecognizer]) {
                
                CGPoint tPoint = [(UIPanGestureRecognizer *)gestureRecognizer translationInView:gestureRecognizer.view];
                
                if (tPoint.x >= 0) {
                    CGFloat y = fabs(tPoint.y);
                    CGFloat x = fabs(tPoint.x);
                    CGFloat af = 30.0f/180.0f * M_PI;
                    CGFloat tf = tanf(af);
                    if ((y/x) <= tf) {
                        return YES;
                    }
                    return NO;
                    
                }else{
                    return NO;
                }
            }
        }
        
        return YES;
    }

    貌似可以了! 欧耶!

    可如果tableView也有右划呢......

    史上最详细的iOS之事件的传递和响应机制-原理篇

  • 相关阅读:
    数组相关操作
    控制结构和函数
    调用函数和方法
    常用类型、算术和操作符重载
    函数式 CSS (FCSS)
    Javascript 封装问题
    认识javascript中的作用域和上下文
    Javascript 继承-原型的陷阱
    解耦你的HTML,CSS和JAVASRIPT
    网格如此简单
  • 原文地址:https://www.cnblogs.com/Milo-CTO/p/7493906.html
Copyright © 2020-2023  润新知