iOS MapKit 更改地图视图地图类型会导致注释图像更改为图钉?
任何有关以下错误的建议将不胜感激。
我使用以下代码将自定义图像添加到注释中。
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isMemberOfClass:[MKUserLocation class]])
{
return nil;
}
if ([annotation isMemberOfClass:[SpectatorPin class]])
{
SpectatorPin *sp = (SpectatorPin *)annotation;
MKAnnotationView *view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"specPin"];
if (view == nil) {
view = [[[MKPinAnnotationView alloc] initWithAnnotation:sp reuseIdentifier:@"specPin"] autorelease];
}
view.image = [UIImage imageNamed:@"mylocation20x20.png"];
view.canShowCallout = YES;
view.annotation=annotation;
return view;
}
//Should not get here
return nil;
}
图像最初显示正常。
我有一个分段控件,可以更改地图类型(标准、卫星、混合)。标准是默认值。一旦我选择卫星,图像立即变为图钉。不会再次调用mapView:viewforAnnotation方法。
问候,
吉姆
Any suggestions on what is wrong with the following would be appreciated.
I am adding a custom image to an annotation using the following code.
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isMemberOfClass:[MKUserLocation class]])
{
return nil;
}
if ([annotation isMemberOfClass:[SpectatorPin class]])
{
SpectatorPin *sp = (SpectatorPin *)annotation;
MKAnnotationView *view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"specPin"];
if (view == nil) {
view = [[[MKPinAnnotationView alloc] initWithAnnotation:sp reuseIdentifier:@"specPin"] autorelease];
}
view.image = [UIImage imageNamed:@"mylocation20x20.png"];
view.canShowCallout = YES;
view.annotation=annotation;
return view;
}
//Should not get here
return nil;
}
The image is displayed properly initially.
I have a segment control which changes the map type (standard, satellite, hybrid). Standard is the default. As soon as I select satellite the image immediately changes to a pin. The mapView:viewforAnnotation method is not called again.
Regards,
Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于自定义图像,您可以使用 MKAnnotationView 而不是 MKPinAnnotationView。
For custom image, you might use MKAnnotationView instead of MKPinAnnotationView.
发现这个:
iPhone 核心位置:地图时自定义图钉图像消失类型更改
链接到此:
为什么自定义 MKMapView 注释图像在触摸时消失?
Found this:
iPhone Core Location: Custom pin image disappears when map type changes
which linked to this:
Why does a custom MKMapView annotation image disappear on touch?
试试这个:
Try this: