Search code examples
iosobjective-cgesture

Add gesture recognizer to MKPointAnnotation


I'm junior in Objective-C. I've a task to add gesture recognizer to MKPointAnnotation.I've heard it's possible to do via MKMapView delegate.But I didn't understand it yet. So, I've a map, which is present via MKPointAnnotation and I've one or more geomarks, which are present via MKPointAnnotation. How to decide this task? My code example:

MKPointAnnotation *newPinAnnotation = [[MKPointAnnotation alloc]init];
CLLocationCoordinate2D pinCoordinate;
pinCoordinate.latitude = self.userLocation.coordinate.latitude;
pinCoordinate.longitude = self.userLocation.coordinate.longitude;
newPinAnnotation.coordinate = pinCoordinate;
[self.mapView addAnnotation:newPinAnnotation];

Solution

  • I don't understand completely, which action you would like to implement. But I think that it will help you. You should implement one or both of these MKMapViewDelegate methods:

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view;
    
    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState 
       fromOldState:(MKAnnotationViewDragState)oldState