• UIGestureRecognizer 事件冲突


    当你程序的view使用了手势UIGestureRecognizer,而你在这个view上面又添加了按钮,那么按钮的响应回调事件方法是不会被调用的,但是按钮是可以看到被按下的高亮效果。(ios4,ios5的bug,ios6就没有了)
    因为 根据响应链来看,这个view上的所有触摸事件都被手势给吸收了,所以要解决这个bug,要给这个手势代理加一些事件过滤,对button事件就不要拦截独吞了。代码如下:

    - (void)addGestureRecognizer{
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                             action:@selector(hiddenKeyboard)];
        tap.delegate = self;
        self.gestureOfHiddenKeyboard = tap;
        [self.view addGestureRecognizer:tap];
        [tap release];
    }

    #pragma mark UIGestureRecognizerDelegate
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
       
        if ([touch.view isMemberOfClass:[UIButton class]]) {
            //放过button点击拦截
            return NO;
        }else{
            return YES;
        }
       
    }

  • 相关阅读:
    realsense d435i qt 测试
    realsense d435i 数据 测试
    realsense d435i测试
    ubuntu torch GPU yolov5
    IfcLayeredItem
    ubuntu大服务器 pytorch环境配置
    condarc内容
    realsense point cloud
    yolov5 环境配置
    pip error
  • 原文地址:https://www.cnblogs.com/ldc529/p/3822825.html
Copyright © 2020-2023  润新知