Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 views
in Technique[技术] by (71.8m points)

iphone - Changing Color/Alpha/Filter to MKMapView iOS 6

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?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...