需求:
点击父View做一件事,点击子View做另一件事
如果这个子View恰巧是一个UIImageView
方式:
UIImageView *AutoCode = [[UIImageView alloc] init];
AutoCode.image = [UIImage imageNamed:@"getPassCodeNew"];
[AutoCode setFrame:CGRectMake(10, 200, self.view.frame.size.width - 20, 200)];
AutoCode.userInteractionEnabled = YES;
UITapGestureRecognizer *tapImage = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_loginAction)];
[AutoCode addGestureRecognizer:tapImage];
[scrollView addSubview:AutoCode];
同时父View也注册一个手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognizer:)];
// tap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tap];
子View的成功不响应他爹的事件,而是专心响应自己的事件了 -。-。
简书看起来不错,所以以后记录问题什么的都搬到这来了0.0.