将颜色/ Alpha /滤镜更改为MKMapView iOS 6

Eri*_*ric 5 iphone core-graphics mkmapview

有没有办法将CI过滤器应用于MKMapViews?或类似的东西?我试图让我的基于地图的应用看起来如此米色.有没有办法应用RGBA过滤器?

任何帮助/教程方向表示赞赏.我在本机文档中看不到任何关于改变外观的内容MKMapView.

Tim*_*ddy 16

我不认为您可以在将图像渲染到屏幕之前更改图像.但是,您可以在整个世界中使用MKOverlayView来实现相同的效果.以下应该可以工作,但只是为了让你开始,它就像伪代码一样对待它.

@interface MapTileOverlay : NSObject <MKOverlay>
@end

@implementation MapTileOverlay
-(id)init {
    self = [super init];
    if(self) {
        boundingMapRect = MKMapRectWorld;
        coordinate = MKCoordinateForMapPoint(MKMapPointMake(boundingMapRect.origin.x + boundingMapRect.size.width/2, boundingMapRect.origin.y + boundingMapRect.size.height/2));
    }
    return self;
}
@end


@interface MapTileOverlayView : MKOverlayView
@end

@implementation MapTileOverlayView
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
    CGContextSetBlendMode(context, kCGBlendModeMultiply);  //check docs for other blend modes
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.5);  //use whatever color to mute the beige
    CGContextFillRect(context, [self rectForMapRect:mapRect]);
}
@end
Run Code Online (Sandbox Code Playgroud)

你需要有一些实现MKMapViewDelegate协议的类来创建视图......

@interface MapViewDelegate : NSObject<MKMapViewDelegate>
@end

@implementation MapViewDelegate
-(MKOverlayView*)mapView:(MKMapView*)mapView viewForOverlay:(id<MKOverlay>)overlay {
    if([overlay isKindOfClass:[MapTileOverlay class]]) {
        return [[MapTileOverlayView alloc] initWithOverlay:overlay];
    }
    return nil;
}
Run Code Online (Sandbox Code Playgroud)

最后,在初始化地图后,您需要在地图上设置委托并添加覆盖...您必须在添加覆盖之前设置委托...

MapViewDelegate* delegate = [[MapViewDelegate alloc] init];  //you need to make this an iVar somewhere
[map setDelegate:delegate];
[map addOverlay:[[MapTileOverlay alloc] init]];
Run Code Online (Sandbox Code Playgroud)

  • 我尝试使用你的方法,覆盖效果很好,但似乎没有应用混合模式.有什么想法吗? (2认同)