iOS事件传递

作者 : 开心源码 本文共1262个字,预计阅读时间需要4分钟 发布时间: 2022-05-13 共177人阅读

假如想让一个控件能有点击效果,那么该控件的所有父控件,及父控件以上的父控件,还有该控件本身,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(@"点击了黄色模块了");    }];}
说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » iOS事件传递

发表回复