0
我有一个注释引脚,用于显示当前可以拖动的搜索位置。这个注解只是一个普通的MKPointAnnotation,然后我改变了viewForAnnotation方法中的图像。这是好的,直到我开始拖动注释,然后注释更改为默认的红色针脚并丢失我设置的自定义图像。iOS 7注释引脚图像在引脚被拖动时发生变化
我创建并添加这样的注解:
MKPointAnnotation *userAnnotation = [[MKPointAnnotation alloc] init];
[userAnnotation setCoordinate:userCoordinate];
[userAnnotation setTitle:@"My Location"];
[userAnnotation setSubtitle:@"Drag to move - Press to reset"];
[self.mapView addAnnotation:userAnnotation];
然后我这样设置annotationView:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
....
[annotationView setImage:[UIImage imageNamed:@"locationpin"]];
[annotationView setDraggable:YES];
[annotationView.layer setZPosition:999];
return annotationView;
我实现方法didChangeDragState:fromState:像这样:
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState
fromOldState:(MKAnnotationViewDragState)oldState {
if (newState == MKAnnotationViewDragStateEnding) {
CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
self.mockLocation = [[CLLocation alloc] initWithLatitude:droppedAt.latitude longitude:droppedAt.longitude];
NSLog(@"%@ mock location set to %f %f", [self class], droppedAt.latitude, droppedAt.longitude);
[self plotStations];
}
}
我不记得这个问题在iOS 6上,但它肯定存在于iOS 7上。
那么,如何让它在拖动之前,之中和之后保留其图像?
我设法重新创建默认动画。将可能的时候发布代码... –