The default pin drop animation doesn't work in my app, here is some code I wrote:
- (void)viewDidLoad {
/*
some code...
*/
[theMapView addAnnotation:addAnnotation];
[addAnnotation release];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
MKPinAnnotationView *annoView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"current"];
annoView.animatesDrop = YES;
annoView.pinColor = MKPinAnnotationColorGreen;
return annoView;
}
Right now the pin just appear in the screen as default red one without any animation, the MKMapViewDelegate
protocol has been adopted, anyone can see what's wrong here?
First use:
[yourMap_view setDelegate:self];
in ViewDidLoad
Then call this for the drop animation :
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
if(annotation!= map_view.userLocation)
{
static NSString *defaultPin = @"pinIdentifier";
pinView = (MKPinAnnotationView*)[map_view dequeueReusableAnnotationViewWithIdentifier:defaultPin];
if(pinView == nil)
pinView = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPin]autorelease];
pinView.pinColor = MKPinAnnotationColorPurple; //Optional
pinView.canShowCallout = YES; // Optional
pinView.animatesDrop = YES;
}
else
{
[map_view.userLocation setTitle:@"You are Here!"];
}
return pinView;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With