MapView自定义Pin图像问题 [英] MapView Custom Pin Image Issue
本文介绍了MapView自定义Pin图像问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经改变了我的MapView引脚图像,但是我遇到了这个问题,有些问题不会改变引脚图像,有些会改变。问题出在哪里?我添加了一个例子。
I have changed my MapView pin image but I am getting this problem that some of the point wont change the pin image and some of them change. Where would be the problem? I have added an example.
我的代码:
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
MKAnnotationView *pinView = nil;
if(annotation != locationMap.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *)[locationMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinAnnotation == nil )
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinAnnotation.canShowCallout = YES;
pinAnnotation.animatesDrop = YES;
pinAnnotation.enabled = YES;
//pinAnnotation.image = [UIImage imageNamed:@"pin.png"];
pinView.image = [UIImage imageNamed:@"pin.png"];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
}
return pinAnnotation;
return pinView;
}
推荐答案
使用常规MKAnnotationView,不是MKPinAnnotationView子类。即使您可以设置图像,也不能保证它会粘住,因为它可以并且会再次将引脚图像设置回来。
Use a regular MKAnnotationView, not the MKPinAnnotationView subclass. Even though you can set the image it isn't guaranteed to stick because it can and will set the pin image back again.
这篇关于MapView自定义Pin图像问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文