将颜色/ Alpha /滤镜更改为MKMapView iOS 6 [英] Changing Color/Alpha/Filter to MKMapView iOS 6

查看:109
本文介绍了将颜色/ Alpha /滤镜更改为MKMapView iOS 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to apply CI Filters to MKMapViews? Or something similar? I'm trying to not have my map based app looks so beige. Is there way to apply RGBA filters?

任何帮助/教程方向表示赞赏。我在原生文档中没有看到任何关于改变 MKMapView 的外观的内容。

Any help/tutorials direction appreciated. I see nothing in the native documentation that talks about changing look for MKMapView.

推荐答案

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

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. 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

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

You need to have some class that implements the MKMapViewDelegate protocol to create the view...

@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]];

这篇关于将颜色/ Alpha /滤镜更改为MKMapView iOS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆