有没有办法将CI过滤器应用于MKMapViews
?还是类似的东西?我试图不让我的基于地图的应用程序看起来如此米色。有没有办法应用RGBA
过滤器?
任何帮助/教程方向表示赞赏。我在本机文档中没有看到任何关于更改外观的内容 MKMapView
.
我认为您无法在图像渲染到屏幕之前更改图像。 但是,您可以在整个世界上使用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
您需要一些实现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;
}
最后,初始化地图后,您需要在地图上设置委托并添加叠加层...您必须在添加覆盖之前设置委托...
MapViewDelegate* delegate = [[MapViewDelegate alloc] init]; //you need to make this an iVar somewhere
[map setDelegate:delegate];
[map addOverlay:[[MapTileOverlay alloc] init]];
您可以在地图视图的顶部添加视图,几乎透明,略带颜色(例如蓝色以补偿棕色。