解決方案:
在我的頭(.h),我增加了委託:
@interface myVC : UIViewController <UIGestureRecognizerDelegate>
在.M:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[self.mapView addGestureRecognizer:tap];
tap.delegate = self;
注意的委託聲明Nirav說需要的是添加
然後我添加Nirav的代碼,但改變了IF語句:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (([touch.view isKindOfClass:[MKPinAnnotationView class]]) || ([touch.view isKindOfClass:[MKAnnotationView class]]))
{
return NO;
}
return YES;
}
來源
2017-02-11 07:10:56
Guy
非常感謝這讓我走上了正確的道路,但我不得不爲MKAnnotationView添加一個額外的測試,因爲MKPinAnnotationView在我點擊Annotation時沒有被識別。參見下面的擴展代碼。 – Guy