MkMapView取消加载谷歌瓷砖 [英] MkMapView cancel loading google tiles
问题描述
我有一个需要在MkMapView顶部导入叠加贴图的情况。
叠加层完全覆盖下面的谷歌图块,因此不需要加载,加上它增加了应用程序的开销。
I have a case where I need to import an overlay map in top of MkMapView. The overlay totally covers the google tiles below so there is no need loading, plus it adds overhead to the app.
有没有办法告诉mkMapView停止加载磁贴?
Is there a way to tell mkMapView to stop loading tiles?
推荐答案
实际上有两种方法可以实现真正的隐藏Google磁贴方法(johndope解决方案只放一个覆盖在它上面,但不会阻止瓷砖加载。)
Actually there are 2 ways to implement the real "Hide Google tiles" method (johndope solution only puts an overlay on top of it but doesn't prevent the tiles from loading).
请注意,下面描述的选项可能会使您的申请被拒绝,而选项2则不会,但是更复杂。
Beware that option one described below might get your application rejected while option 2 will not but is a bit more complex.
公共部分:检索 MKMapTileView
对象
Common Part: Retrieve the MKMapTileView
object
每个 MKMapView
里面都有一个未记录的类: MKMapTileView
。检索它不是拒绝的理由。在此代码中, MKMapView
实例将被称为 mapView
Inside each MKMapView
lies an undocumented class of type: MKMapTileView
. Retrieving it is NOT a reason for rejection. In this code the MKMapView
instance will be called 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];
这将阻止未记录的方法 setDrawingEnabled
to在 MKMapTileView
实例上调用。
This will prevent the undocumented method setDrawingEnabled
to be called on the MKMapTileView
instance.
选项2:方法调整
在你的控制器实现之外,你会写一些像:
Outside of your controller implementation you will write someting like:
// 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);
}
代码中的某处(加载地图视图后!):
And somewhere in your code (once your map view is loaded!) :
// 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);
}
希望这有助于任何人,此代码最初在此博文。
Hope this helps anyone, this code was originally described in this blog post.
这篇关于MkMapView取消加载谷歌瓷砖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!