2013-05-02 23 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,並給我需要的東西。