iOS事件传递

作者: 码工人生 | 来源:发表于2020-01-06 21:41 被阅读0次

如果想让一个控件能有点击效果,那么该控件的所有父控件,及父控件以上的父控件,还有该控件本身,userInteractionEnabled 一定要为YES;而该控件的子控件userInteractionEnabled 不管是YES还是NO都不影响。


1578317797751.jpg

代码如下

/// 事件点击层级
- (void)testOne{
    self.redView = [[UIView alloc]init];
    [self.view addSubview:self.redView];
    [self.redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(300);
        make.top.equalTo(self.view.mas_top).offset(84);
    }];
    self.redView.backgroundColor = [UIColor redColor];
    self.redView.userInteractionEnabled = YES;//此处必须为YES
    
    self.yellowView = [[UIView alloc]init];
    [self.redView addSubview:self.yellowView];
    [self.yellowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.redView);
        make.width.height.mas_equalTo(200);
    }];
    self.yellowView.backgroundColor = [UIColor yellowColor];
    self.yellowView.userInteractionEnabled = YES;//此处必须为YES
    
    
    self.cyanView = [[UIView alloc]init];
    [self.yellowView addSubview:self.cyanView];
    [self.cyanView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.yellowView);
        make.height.mas_equalTo(100);
        make.width.mas_equalTo(100);
    }];
    self.cyanView.backgroundColor = [UIColor cyanColor];
    self.cyanView.userInteractionEnabled = YES;//此处也可以为NO或者YES
    
    
    [self addEventMethod];
}
- (void)addEventMethod{
    [self.yellowView bk_whenTapped:^{
        NSLog(@"点击了黄色模块了");
    }];
}

相关文章

  • iOS 响应链

    iOS开发 - 事件传递响应链iOS 响应者链,事件的传递事件传递之响应链Cocoa Touch事件处理流程--响...

  • 深入浅出iOS事件机制

    深入浅出iOS事件机制事件传递:响应链事件传递响应链

  • iOS事件,原来如此

    精简地说:iOS事件分为传递和响应两个部分。 事件传递(建立传递链): iOS系统检测到手指触摸(Touch)操作...

  • 初识iOS事情处理机制

    参考:史上最详细的iOS之事件的传递和响应机制-原理篇iOS触摸事件全家桶史上最详细的iOS之事件的传递和响应机制...

  • iOS响应者链

    参考好文 iOS开发-事件传递响应链,用运行时分析 iOS事件传递:响应者链[译] http://www.jian...

  • 事件层级原理 响应链

    iOS事件 运动事件,远程控制事件、触摸事件 触摸事件 事件传递的顺序 当点击红色的时候 打印为 事件传递的方法 ...

  • iOS 触摸事件与响应理解

    参考文章: iOS触摸事件的流动 iOS触摸事件的传递与响应 UIViewController UIAppli...

  • iOS之事件的传递和响应机制

    iOS之事件的传递和响应机制

  • ios 事件传递和响应

    史上最详细的iOS之事件的传递和响应机制-原理篇iOS触摸事件传递响应之被忽视的手势识别器工作原理手势事件中can...

  • 二、事件传递链和响应者链

    iOS触摸事件详解iOS开发-事件传递响应链 响应者链 UIResponser包括了各种Touch message...

网友评论

    本文标题:iOS事件传递

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