当mapoverlay可见ios7时隐藏mapview [英] Hiding mapview when mapoverlay is visible ios7

查看:108
本文介绍了当mapoverlay可见ios7时隐藏mapview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在iOS7的mapview顶部有叠加层时,如何隐藏mapview?这段代码曾经在iOS6中运行,但是当我将我的应用程序升级到iOS7时,它停止工作。

How do I hide the mapview when I have an overlay on top of the mapview in iOS7? This snippet of code used to work in iOS6 but when i upgrade my app to iOS7 it cease to work.

NSArray *views = [[[self.mapView subviews] objectAtIndex:0] subviews];

[[views objectAtIndex:0] setHidden:YES];

有任何建议或反馈吗?

推荐答案

用incanus用 MKTileOverlay 表示,在视图控制器中就是这样:

With what incanus said with MKTileOverlay, it is like this in the view controller:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *tileTemplate = @"http://tile.stamen.com/watercolor/{z}/{x}/{y}.jpg";
    MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:tileTemplate];
    overlay.canReplaceMapContent = YES;
    [self.mapView addOverlay:overlay];

    [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(37.54827, -121.98857)];
    self.mapView.delegate = self;
}


-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
    MKTileOverlayRenderer *renderer = [[MKTileOverlayRenderer alloc] initWithOverlay:overlay];
    return renderer;
}

如果你需要控制叠加层如何提供数据,你需要子类 MKTileOverlay 并覆盖 loadTileAtPath:结果:

If you need control over how the overlay feeds the data, you need to subclass MKTileOverlay and override loadTileAtPath:result:

-(void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *, NSError *))result
{
    NSData *tile = [self someHowGetTileImageIntoNSDataBaseOnPath:path];
    if (tile) {
        result(tile, nil);
    } else {
        result(nil, [NSError errorWithDomain: CUSTOM_ERROR_DOMAIN code: 1 userInfo:nil]);
    }
}

MKOverlay protocol需要 boundingMapRect:,它应返回此叠加层覆盖的矩形区域的MKMapRect。但是,我个人发现如果我自己覆盖它,它会使先前的 canReplaceMapContent = YES 设置无效,因为Apple可能不喜欢显示空白的灰色地图。所以我只是让MKTileMapOverlay处理它。

The MKOverlay protocol requires boundingMapRect:, which should returns MKMapRect for the rectangular region that this overlay covers. However, I personally found that if I override it myself, it voids the prior canReplaceMapContent = YES setting as Apple probably does not like to show a blank gray map. So I just let MKTileMapOverlay handles it instead.

如果你的叠加层实际上不是贴图,那么MKTileOverlay并不真正适用。但我认为你可能会伪造它但总是在 loadTileAtPath:result:中报告nil数据,并通过另一个叠加层添加你的真实叠加层。另一种选择是用黑色多边形叠加层覆盖整个世界,但是毫无疑问的用户可能会在不知不觉中传输比他/她更喜欢的数据。

If your overlay is not actually tiles, then MKTileOverlay does not really apply. But I think you probably can fake it but always reporting nil data within loadTileAtPath:result:, and add your real overlay via another overlay. Another option would be just cover the whole world with black polygon overlay, but then the unsuspecting user would possibly be unknowingly streaming more data than he/she likes.

这篇关于当mapoverlay可见ios7时隐藏mapview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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