0

我有这段代码可以删除并在我的地图中添加一个新图钉:

- (IBAction)setLocation:(id)sender{

    NSMutableArray *toRemove = [NSMutableArray arrayWithCapacity:1];
    for (id annotation in map.annotations)
        if (annotation != map.userLocation)
            [toRemove addObject:annotation];
    [map removeAnnotations:toRemove];


    MKPointAnnotation *annotationPoint = [[[MKPointAnnotation alloc] init]autorelease];
    annotationPoint.coordinate = map.userLocation.coordinate;
    annotationPoint.title = @"Position";
    [map addAnnotation:annotationPoint];

    MKPinAnnotationView *pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotationPoint reuseIdentifier:@"Pin"] autorelease];
    pinView.pinColor = MKPinAnnotationColorRed;
    pinView.canShowCallout = YES;
    //pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.animatesDrop = TRUE;


}

但我设置了我的 pin 它不做动画但我设置了 animatesDrop = true,为什么?

4

2 回答 2

1

看来您没有将 pinView 添加到地图中。

于 2012-07-17T22:44:47.263 回答
0

我认为这可能会有所帮助。我相信您可以尝试使用MKMapViewDelegate(Apple 文档,查看 MapCallouts 示例项目)方法:

   - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation
{
    MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];

// alter properties of the customPinView

    return customPinView; // if you return nil... then the MKPinAnnotation default will be dropped.
}

确保<MKMapViewDelegate>在标头中添加协议

于 2012-07-17T23:21:28.637 回答