在MKPinAnnotationView后面添加图像 [英] Add image behind MKPinAnnotationView

查看:97
本文介绍了在MKPinAnnotationView后面添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MKPinAnnotationView后添加图像。看起来在这里应该很容易做到这一点:

I'm trying to add an image behind a MKPinAnnotationView. Seems like it should be rather easy to just do this in here:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
 for (MKAnnotationView *aView in views)
  [[aView superview] addSubview:imageView];
}

但我遇到的问题是孩子子视图到pin将呈现在它之上而不是它背后。

But the problem I am having in doing that is that the child subview to the pin will render on top of it not BEHIND it.

我也尝试过:

 for (MKAnnotationView *aView in views)
  [[aView superview] insertSubview:imageView atIndex:1];

这个问题是,当它在引脚后面时,一旦地图重新定位,图像漂浮在屏幕上。

The problem with this is that, while it IS behind the pin, as soon as the map is repositioned, the image floats off the screen.

有什么建议吗?谢谢

推荐答案

感谢您的输入,这里基本上是我没有子类化的结果:

Thanks for the input, here's basically what I ended up doing without subclassing:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {

    MKAnnotationView *annView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];

    UIImage *image = [UIImage imageNamed:@"image.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [annView addSubview:imageView];
    [imageView release];

    MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];     
    [annView addSubview:pinView];
    [pinView release];

    return annView;
}

我只需要一个引脚,所以我设置 reuseIdentifier nil

I only needed one pin, so I set reuseIdentifier to nil.

这篇关于在MKPinAnnotationView后面添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆