I have made it so that the UILongPressGestureRecognizer drops a pin, but I want it to be animated. So I try and set the animatesDrop property in the press: method, and I do not get any errors, but it is not working. I do not know if I set the property in the wrong place, or what.
Here is the code.
-(void)viewDidLoad
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self
action:@selector(press:)];
longPress.minimumPressDuration = 0.5f; //user needs to press for 2 seconds
[longPress setDelegate:self];
[worldView addGestureRecognizer:longPress];
[worldView setShowsUserLocation:YES];
}
-(void)press:(UILongPressGestureRecognizer *)recognizer
{
CGPoint touchPoint = [recognizer locationInView:worldView];
CLLocationCoordinate2D touchMapCoordinate = [worldView convertPoint:touchPoint toCoordinateFromView:worldView];
if (UIGestureRecognizerStateBegan == recognizer.state) {
BNRMapPoint *mp = [[BNRMapPoint alloc]initWithCoordinate:touchMapCoordinate
title:@"Some Title"];
[worldView addAnnotation:mp];
[mp setAnimatesDrop:YES];
}
}
Any help would be appreciated.
setAnimatesDrop:
is a method of MKPinAnnotationView, while your BNRMapPoint
seems like annotation class implementing the MKAnnotation
protocol.
You need to provide mapView:viewForAnnotation:
method to return an MKPinAnnotationView for your annotation, where you can set MKPinAnnotationView's animatesDrop
property to YES
.
You can refer to Apple's sample code MapCallouts.