在MKMapView中更改MKMapType并为注释保留自定义pinImage [英] Change MKMapType in MKMapView and keep custom pinImage for annotations
问题描述
我为我的注释设置了自定义pinImage,当我将类型更改为 MKMapTypeHybrid
时,它会将pinImage设置恢复为标准引脚。
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.
我在地图视图控制器的 viewWillAppear
方法中设置了mapType。我正在为这样的注释设置我的pinImage(为了清晰起见缩短了):
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;
}
有没有办法使用 setImage
并通过代码设置mapType?
Is there any way to use setImage
and set the mapType via code?
推荐答案
此问题的解决方案是使用MKAnnotationView而不是MKPinAnnotationView 。我以前一直使用MKPinAnnotationView是有充分理由但后来在没有将实例化类更改为MKAnnotationView的情况下向引脚添加了自定义图像。
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.
现在,我认为它可能是错误的框架行为。如果您要让MKPinAnnotationView接受setImage调用,请确保在更改mapTypes时它正确处理它。如果您只想让他们做针脚,那么不要对呼叫做任何事情。好吧。
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.
这篇关于在MKMapView中更改MKMapType并为注释保留自定义pinImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!