анимация выпадения булавки - PullRequest
10 голосов
/ 23 сентября 2011

Анимация вывода пин-кода по умолчанию не работает в моем приложении, вот код, который я написал:

- (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;
}

Прямо сейчас значок выводится на экран как красный по умолчанию без анимации, протокол MKMapViewDelegate принят, кто-нибудь может увидеть, что здесь не так?

1 Ответ

13 голосов
/ 23 сентября 2011

Первое использование:

[yourMap_view setDelegate:self];

в ViewDidLoad

Затем вызовите это для анимации отбрасывания:

- (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;
}
...