10

私のアプリではデフォルトのピン ドロップ アニメーションが機能しません。ここに私が書いたコードをいくつか示します。

- (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プロトコルが採用されています。誰でもここで何が問題なのかを確認できますか?

4

1 に答える 1

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;
}
于 2011-09-23T12:20:12.530 に答える