将子视图添加到地图上方但注释视图下方的MKMapView? [英] Adding subview to MKMapView that's above the map but below the annotation views?

查看:160
本文介绍了将子视图添加到地图上方但注释视图下方的MKMapView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在构建的应用,我有一个自定义的旧地图效果PNG,我想在MKMapView视图上叠加。不幸的是,我尝试这样做的方式都不对:

For an app I'm building, I have a custom "old map" effect PNG that I'd like to overlay on the MKMapView view. Unfortunately, neither way I've tried to do this is exactly right:


  1. 将子视图添加到MKMapView(问题:UIImageView用于PNG被放置在上面注释引脚,这看起来很奇怪

  2. 使图像成为注释视图本身并将其置于其他视图之下(问题:滚动,我必须移动注释视图图像,有一段时间只有常规地图而不是旧时效 - 。

  1. Add a subview to the MKMapView (issue: the UIImageView for the PNG gets placed above the Annotation pins, which looks weird
  2. Make the image an annotation view itself and place it below the other ones (issue: on scroll, I have to move the annotation view image, and for a while there's just the regular map instead of the old-timey-effect).

我基本上想要实现的是有一个子视图,它位于maptiles上方,但在注释视图下方,并且在用户滚动时会保持稳定 - 任何想法?

What I basically want to accomplish is having a subview that is layered above the maptiles but below the annotation views, and that will hold steady while the user scrolls around—any thoughts?

推荐答案

请注意,所有 MKMapView 子视图层次结构,注释,行为等都在内部私有 MKMapViewInternal 类如此改变任何东西(在我建议或其他方面)在此结构中可能会导致您的应用程序被拒绝从Appstore。


我没有完整的解决方案,只是一个想法。我的想法是使叠加视图与注释视图具有相同的超视图,并确保将注释放在叠加层上。在MKMapViewDelegate中我们实现:

Note that all MKMapView subviews hierarchy, annotations, behaviour etc proceeds in internal private MKMapViewInternal class so changing anything (in a way I suggest or another) in this structure may cause your application to be rejected from Appstore.

I do not have a full solution, just an idea. My idea is to make an overlay view have the same superview as annotation views and ensure that annotations will be placed over our overlay. In MKMapViewDelegate we implement:

- (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views{
    if (views.count > 0){
        UIView* tView = [views objectAtIndex:0];

        UIView* parView = [tView superview];
        UIView* overlay = [tView viewWithTag:2000];
        if (overlay == nil){
            overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:MY_IMAGE_NAME]];
            overlay.frame = parView.frame; //frame equals to (0,0,16384,16384)
            overlay.tag = 2000;
            overlay.alpha = 0.7;
            [parView addSubview:overlay];
            [overlay release];
        }

        for (UIView* view in views)
            [parView bringSubviewToFront:view];
    }
}

这段代码可以满足你想要的一半 - 你获取地图图块和注释之间的视图。剩下的任务是根据地图滚动/缩放更改自定义叠加视图框(如果找到方法,我会发布)。

This code does a half of what you want - you get a view placed between map tiles and annotations. The remaining task is to change custom overlay view frame according to map scrolling/zooming (I'll post if I find the way).

这篇关于将子视图添加到地图上方但注释视图下方的MKMapView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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