2013-05-02 21 views
2

我有一个自定义MKOverlayMKOverlayView。当创建MKOverlayView,我可以设置视图的alphaMKOverlayView并更改它的阿尔法

-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { 
    DatasetOverlay *datasetOverlay = (DatasetOverlay *)self.overlay; 

    UIImage *image = [UIImage imageWithData:datasetOverlay.imageData]; 

    CGImageRef imageReference = image.CGImage; 

    MKMapRect theMapRect = [self.overlay boundingMapRect]; 
    CGRect theRect = [self rectForMapRect:theMapRect]; 

    CGContextScaleCTM(context, 1.0, -1.0); 
    CGContextTranslateCTM(context, 0.0, -theRect.size.height); 
    CGContextSetAlpha(context, 1); 
    CGContextDrawImage(context, theRect, imageReference); 
} 

但我希望能够更改视图的alpha的平局之后。

我该怎么做?

我还没有很多Core Graphics的工作。

+1

你是否继承了你的MKOverlay?如果是这样,[self setAlpha:.7]; – 2013-05-02 19:47:24

+0

MKOverlay没有alpha属性。 – Padin215 2013-05-02 20:49:34

+0

但MKOverlayView呢。 – Padin215 2013-05-02 20:55:08

回答

0
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { 
    DLog(@"Fired"); 
    DatasetOverlay *datasetOverlay = (DatasetOverlay *)self.overlay; 

    UIImage *image = [UIImage imageWithData:datasetOverlay.imageData]; 

    CGImageRef imageReference = image.CGImage; 

    MKMapRect theMapRect = [self.overlay boundingMapRect]; 
    CGRect theRect = [self rectForMapRect:theMapRect]; 



    CGContextScaleCTM(context, 1.0, -1.0); 
    CGContextTranslateCTM(context, 0.0, -theRect.size.height); 
// CGContextSetAlpha(context, 1); 
    CGContextDrawImage(context, theRect, imageReference); 
} 

K,感谢@ ttarules的评论,我做了一些测试,并意识到我需要删除CGContextSetAlpha(),只是设置alphaMKOverlayView的alpha属性。我现在可以在初始化之外更改alpha,并给我需要的东西。