ios – MkMapView取消加载谷歌瓷砖

ios – MkMapView取消加载谷歌瓷砖,第1张

概述我有一个案例,我需要在MkMapView的顶部导入叠加地图. 叠加层完全覆盖了下面的谷歌图块,因此不需要加载,而且还增加了应用程序的开销. 有没有办法告诉mkMapView停止加载瓷砖? 实际上有两种方法可以实现真正的“隐藏Google磁贴”方法(johndope解决方案只在其上面放置一个叠加但不会阻止加载磁贴). 请注意,下面描述的选项可能会使您的应用程序被拒绝,而选项2则不会,但会更复杂一些. 我有一个案例,我需要在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: implementationstatic voID (*_origDrawLayerInContext)(ID,SEL,CALayer*,CGContextRef);// this will overrIDe the drawLayer:inContext: methodstatic 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 objectMethod  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取消加载谷歌瓷砖所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1109391.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存