ios – MkMapView取消加载谷歌瓷砖

我有一个案例,我需要在MkMapView的顶部导入叠加地图.
叠加层完全覆盖了下面的谷歌图块,因此不需要加载,而且还增加了应用程序的开销.

有没有办法告诉mkMapView停止加载瓷砖?

解决方法

实际上有两种方法可以实现真正的“隐藏Google磁贴”方法(johndope解决方案只在其上面放置一个叠加但不会阻止加载磁贴).

请注意,下面描述的选项可能会使您的应用程序被拒绝,而选项2则不会,但会更复杂一些.

公共部分:检索MKMapTileView对象

每个MKMapView内部都有一个未记录的类型:MKMapTileView.检索它不是拒绝的理由.在此代码中,MKMapView实例将被称为mapView

UIView* scrollview = [[[[mapView subviews] objectAtIndex:0] subviews] objectAtIndex:0];
UIView* mkTiles = [[scrollview subviews] objectAtIndex:0]; // <- MKMapTileView instance

选项1:未记录的方法(!!可能是拒绝的原因!!)

if ( [mkTiles respondsToSelector:@selector(setDrawingEnabled:)])
    [mkTiles performSelector:@selector(setDrawingEnabled:) withObject:(id)NO];

这将阻止在MKMapTileView实例上调用未记录的方法setDrawingEnabled.

选项2:方法调配

在控制器实现之外,你会写一些像:

// Import runtime.h to unleash the power of objective C 
#import <objc/runtime.h>

// this will hold the old drawLayer:inContext: implementation
static void (*_origDrawLayerInContext)(id,SEL,CALayer*,CGContextRef);

// this will override the drawLayer:inContext: method
static void OverrideDrawLayerInContext(UIView *self,SEL _cmd,CALayer *layer,CGContextRef context)
{
    // uncommenting this next line will still perform the old behavior
    //_origDrawLayerInContext(self,_cmd,layer,context);

    // change colors if needed so that you don't have a black background
    layer.backgroundColor = RGB(35,160,211).CGColor;

    CGContextSetRGBFillColor(context,35/255.0f,160/255.0f,211/255.0f,1.0f);
    CGContextFillRect(context,layer.bounds);
}

在你的代码中的某个地方(一旦加载了地图视图!):

// Retrieve original method object
Method  origMethod = class_getInstanceMethod([mkTiles class],@selector(drawLayer:inContext:));

// from this method,retrieve its implementation (actual work done)
_origDrawLayerInContext = (void *)method_getImplementation(origMethod);

// override this method with the one you created    
if(!class_addMethod([mkTiles class],@selector(drawLayer:inContext:),(IMP)OverrideDrawLayerInContext,method_getTypeEncoding(origMethod)))
{
    method_setImplementation(origMethod,(IMP)OverrideDrawLayerInContext);
}

希望这对任何人都有帮助,这段代码最初是在blog post中描述的.

以上是来客网为你收集整理的ios – MkMapView取消加载谷歌瓷砖全部内容,希望文章能够帮你解决ios – MkMapView取消加载谷歌瓷砖所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。