的檢測子視圖我已經添加了TapGestureRecognizer到我self.view:的UIScrollView和敲擊手勢
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
但是我沒看到標籤!在我的日誌中。
謝謝!我還修改了上面的代碼,使用UIScrollView作爲hitTest和locationInView – Mark