我有这段代码要删除并在我的地图中添加一个新图钉:
- (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,为什么?
答案 0 :(得分:1)
您似乎没有将pinView添加到地图中。
答案 1 :(得分: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>
协议