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上。
那麼,如何讓它在拖動之前,之中和之後保留其圖像?
我設法重新創建默認動畫。將可能的時候發佈代碼... –