【发布时间】:2016-07-07 21:04:04
【问题描述】:
我正在使用UITapGestureRecognizer 来检测在我的屏幕上点击了哪个 UIView,但由于某种原因它只检测到父视图点击,例如下面的代码仅记录父视图标签。我如何检测主视图上存在的子视图点击。请建议。
Inside View did load :-
UITapGestureRecognizer *viewTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionForViewTapped:)];
[self.view addGestureRecognizer:viewTapRecognizer];
-(void) actionForViewTapped:(UITapGestureRecognizer*)sender {
NSLog(@"view tapped");
UIView *view = sender.view;
NSLog(@"view tag is %lu", view.tag); //Always prints parent view tag.
if(view.tag == 10){
NSLog(@"tag1 tapped"); // not called
}
if(view.tag == 20){
NSLog(@"tag 2 tapped"); // not called
}
}
【问题讨论】:
标签: ios objective-c