[英]MKAnnotationView custom image is not shown
I am trying to add a custom image instead of the regular pin on the map. 我试图在地图上添加自定义图像而不是常规图钉。 But it remains a red pin... What am I missing? 但它仍然是一个红色的针...我错过了什么?
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
annView.animatesDrop = TRUE;
annView.image = [UIImage imageNamed:@"CustomPin.png"];
return annView;
}
MKMapView: Instead of Annotation Pin, a custom view MKMapView:自定义视图而不是注释引脚
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
//pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
//pinView.animatesDrop = YES;
pinView.image = [UIImage imageNamed:@"pinks.jpg"]; //as suggested by Squatch
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
Hi just remove one line from your code... annView.animatesDrop = TRUE;
嗨,只需从代码中删除一行... annView.animatesDrop = TRUE;
Remain Code- 保留代码 -
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
annView.image = [UIImage imageNamed:@"CustomPin.png"];
return annView;
}
I found it helpful to look at Apples Documentation and download the sample code. 我发现查看Apples文档并下载示例代码很有帮助。
http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009746 http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009746
They are implementing a custom annotation for their map. 他们正在为他们的地图实现自定义注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.