版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/potato512/article/details/83934899
1、添加长按手势
- (MKMapView *)mapView
{
if (_mapView == nil) {
_mapView = [[MKMapView alloc] init];
}
return _mapView;
}
// 添加长按手势
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.mapView addGestureRecognizer:longPressRecognizer];
2、长按实现方法
- (void)longPress:(UIGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateBegan) {
CGPoint point = [recognizer locationInView:self.mapView ];
CLLocationCoordinate2D touchCoordinate = [self.mapView convertPoint:point toCoordinateFromView:self.mapView ];
NSLog(@"%f %f",touchCoordinate.latitude, touchCoordinate.longitude);
}
}