Ios7 MKMapView隐藏地图分幅并设置透明背景

Ios7 MKMapView隐藏地图分幅并设置透明背景,ios7,mkmapview,mapkit,Ios7,Mkmapview,Mapkit,我试图在地图上显示一些注释。我想使用MKMapView类,因为它处理注释的方式对我来说非常好。但我有自己的自定义地图系统,它可以使用自己的视图。我已经试着实现这个答案中建议的方法swizzling,但我没有运气。瓷砖没有被显示,这是正常的,但背景是不透明的,它有一个类似灰色的颜色。请参见下面的屏幕截图: 黑色路径是我的注释。后面是我自己的地图,我看不见。我肯定它在后面,如果我不添加MKMapView我就能看到它 我知道我在这里尝试的东西很粗糙,但我没有其他选择 链接答案中的swizzling代

我试图在地图上显示一些注释。我想使用
MKMapView
类,因为它处理注释的方式对我来说非常好。但我有自己的自定义地图系统,它可以使用自己的视图。我已经试着实现这个答案中建议的方法swizzling,但我没有运气。瓷砖没有被显示,这是正常的,但背景是不透明的,它有一个类似灰色的颜色。请参见下面的屏幕截图:

黑色路径是我的注释。后面是我自己的地图,我看不见。我肯定它在后面,如果我不添加
MKMapView
我就能看到它

我知道我在这里尝试的东西很粗糙,但我没有其他选择

链接答案中的swizzling代码为:

我定义:

// 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);
}

您的磁贴系统无法用作MKMapView的源吗?如果可以,那么您就不必保持两个贴图对象同步
UIView* scrollview = [[[[mapView subviews] objectAtIndex:0] subviews] objectAtIndex:0];
UIView* mkTiles = [[scrollview subviews] objectAtIndex:0]; // <- MKMapTileView instance

// 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);
}