iOS MapView:点击添加注释,但如果现有注释点击则不添加

Dou*_*olo 7 mapkit mkmapview mkannotation ios

我有一个UITapGestureRecognizer设置,可以在用户点击的地图上添加注释.我遇到的问题是当用户点击现有注释以查看工具提示时,工具提示会弹出,但另一个注释会添加到点击注释后面的地图中.有没有办法检测是否在添加注释之前点击并返回注释?

这是我的viewDidLoad:

UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(foundTap:)];
singleTapRecognizer.numberOfTapsRequired = 1;
[self.mapView addGestureRecognizer:singleTapRecognizer];
Run Code Online (Sandbox Code Playgroud)

我的触摸功能:

-(IBAction)foundTap:(UITapGestureRecognizer *)recognizer
{
    CGPoint point = [recognizer locationInView:self.mapView];

    CLLocationCoordinate2D tapPoint = [self.mapView convertPoint:point toCoordinateFromView:self.view];

    AGIAnnotation * annotation = [[AGIAnnotation alloc] initWithCoordinate:tapPoint];
    // Some other stuff

    [self.mapView addAnnotation:annotation];
}
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

Mic*_*han 6

有一个UIGestureRecognizerDelegate协议

如果触摸在现有工具提示上,则实施gestureRecognizer:shouldReceiveTouch:并返回NO.像这样的东西:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isKindOfClass:[MKPinAnnotationView class]])
    {
        return NO;
    }
    return YES;
}
Run Code Online (Sandbox Code Playgroud)