当给UIView添加Animation动画时,项目须要添加点击事件。
可是使用UIButton无效,不响应点击事件。
baidu / google 之。
发现UILayer不响应事件。
换一种思路,发现能够给整个视图添加点击手势,而后判断点击位置来触发事件。动画
//建立手势添加到视图上 self.tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)]; [self.view addGestureRecognizer:self.tapGesture]; #pragma mark - 点击 /** 点击事件*/ -(void)click:(UITapGestureRecognizer *)tapGesture { CGPoint touchPoint = [tapGesture locationInView:self]; //遍历当前视图上的子视图的presentationLayer 与点击的点是否有交集 for (UIView *subView in self.view.subviews) { if ([subView.layer.presentationLayer hitTest:touchPoint]) { NSLog(@"点击的是:%@",subView); } } }
收工google