针下降动画

时间:2011-09-23 12:04:55

标签: iphone mkmapview mkpinannotationview

默认的针脚下拉动画在我的应用中不起作用,这里是我写的一些代码:

- (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 个答案:

答案 0 :(得分:13)

首次使用:

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