Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pin drop animation

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?

like image 918
Michael Avatar asked Sep 23 '11 12:09

Michael


1 Answers

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;
}
like image 65
iNoob Avatar answered Oct 20 '22 22:10

iNoob