【问题标题】:IOS: MKPinAnnotationView animated drop don't workIOS:MKPinAnnotationView 动画放置不起作用
【发布时间】:2012-07-17 22:41:15
【问题描述】:

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

- (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,为什么?

【问题讨论】:

    标签: ios uiview mkmapview mkpinannotationview


    【解决方案1】:

    您似乎没有将 pinView 添加到地图中。

    【讨论】:

    • 不,当我调用此 IBaction pinView 时出现...那么您的解决方案是什么?
    【解决方案2】:

    我认为这可能会有所帮助。我相信您可以尝试使用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.
    }
    

    确保在标头中添加&lt;MKMapViewDelegate&gt; 协议

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 2021-03-21
      相关资源
      最近更新 更多