解决方法
实际上有两种方法可以实现真正的“隐藏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); }