Having tried many methods I still haven't found a good and full-proof way of preventing the usual "maps" from being shown behind custom map tiles that I am using. Ultimately I want my app to have a map page consisting only of a custom map.

I am really looking for a solution that is pure iOS and doesn't require any 3rd party software but it would appear difficult.

I have tried 3 methods already:

Number 1, hiding the background map via it's view:

NSArray *views = [[[self.mapView subviews] objectAtIndex:0] subviews];
[[views objectAtIndex:0] setHidden:YES];
  • this however doesn't work on a certain new operating system coming out very soon! The whole screen goes blank. The Apple Developer Forum hasn't provided a solution either

Number 2, Using another blank overlay (e.g. MKCircle) to cover the background map. This works however when scrolling or zooming out quickly, sometimes the overlay flickers off and you can briefly see the background map behind so not ideal.

Number 3, and this is what I have been working on for a few days now is to simply prevent the user from zooming out. Most documented methods tend to use regionDidChangeAnimated or regionWillChangeAnimated, however these do not seem to suddenly stop the map zooming out when pinching - they wait until the pinch movement has finished before taking effect so again it means the background map can be viewed briefly.

So now I am stumped, unless of course I have missed something with these other two methods.

So any help would be much appreciated!

有帮助吗?

解决方案 2

You can't do this in current releases without a third-party library like MapBox. However, the future OS release that you speak of lets you do this.

其他提示

Add this:

-(void)viewDidAppear:(BOOL)animated    
{    
    MKTileOverlay *overlay = [[MKTileOverlay alloc] init];//        initWithURLTemplate:tileTemplate];    
    overlay.canReplaceMapContent = YES;    
    [map addOverlay:overlay];    
    overlay = nil;
}

-(void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *, NSError *))result    
{    
    NSData *tile =nil;    
}

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

It will replace the map content from the background. It worked very well in my case where I am adding an overlay on the whole map and hiding the real map from the user.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top