问题
I have set a custom pinImage for my annotations and when I change the type toMKMapTypeHybrid
it reverts the pinImage setting to the standard pins.
I'm setting the mapType in my viewWillAppear
method of the map view controller. I'm setting my pinImage for the annotations like so (shortened for clarity):
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
MKPinAnnotationView *customAnnotationView=[[[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:@"markerAnnotationView"] autorelease];
UIImage *pinImage = [UIImage imageNamed:@"/pin-image"];
[customAnnotationView setImage:pinImage];
return customAnnotationView;
}
Is there any way to use setImage
and set the mapType via code?
回答1:
The solution to this problem was to use an MKAnnotationView instead of the MKPinAnnotationView. I had previously been using the MKPinAnnotationView for good reason but later added a custom image to the pin without changing the instantiating class to MKAnnotationView.
Now, I think it is probably buggy framework behavior. If you're going to let an MKPinAnnotationView accept a setImage call then make sure that it handles it correctly when you change mapTypes. If you only want them to do pins then don't do anything with the call. Ah well.
来源:https://stackoverflow.com/questions/5136545/change-mkmaptype-in-mkmapview-and-keep-custom-pinimage-for-annotations