简体   繁体   English

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

[英]Changing Color/Alpha/Filter to MKMapView iOS 6

Is there a way to apply CI Filters to MKMapViews ? 有没有办法将CI过滤器应用于MKMapViews Or something similar? 或类似的东西? I'm trying to not have my map based app looks so beige. 我试图让我的基于地图的应用看起来如此米色。 Is there way to apply RGBA filters? 有没有办法应用RGBA过滤器?

Any help/tutorials direction appreciated. 任何帮助/教程方向表示赞赏。 I see nothing in the native documentation that talks about changing look for MKMapView . 我在原生文档中没有看到任何关于改变MKMapView外观的内容。

I don't think you can change the imagery before it is rendered to the screen. 我不认为您可以在将图像渲染到屏幕之前更改图像。 However, you can use an MKOverlayView over the entire world that achieves the same effect. 但是,您可以在整个世界中使用MKOverlayView来实现相同的效果。 The following should work, but treat it like pseudocode just to get you started. 以下应该可以工作,但只是为了让你开始,它就像伪代码一样对待它。

@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

You need to have some class that implements the MKMapViewDelegate protocol to create the view... 你需要有一些实现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;
}

Finally, after you initialize your map, you need to set the delegate on the map and add the overlay...you must set the delegate before you add the overlay... 最后,在初始化地图后,您需要在地图上设置委托并添加覆盖...您必须在添加覆盖之前设置委托...

MapViewDelegate* delegate = [[MapViewDelegate alloc] init];  //you need to make this an iVar somewhere
[map setDelegate:delegate];
[map addOverlay:[[MapTileOverlay alloc] init]];

您可以在地图视图顶部添加一个视图,几乎是透明的,带有轻微的颜色(例如蓝色以补偿棕色。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM