我已经在self.view上添加了一个TapGestureRecognizer:
然而,我在日志中并没有看到这个标签!
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:tap];
[tap release];
这个视图包含一个单独的UIScrollView,其中包含图像和标签。我想检测用户是否点击了标签。
- (void)singleTap:(UIGestureRecognizer*)gestureRecognizer {
CGPoint pt = [gestureRecognizer locationInView:self.view];
UIView *v = [self.view hitTest:pt withEvent:nil];
if ([v isKindOfClass:[UILabel class]]) {
NSLog(@"label!");
return;
}
// else do other stuff if its not a label
然而,我在日志中并没有看到这个标签!