2012-02-10 47 views
3

你好,我想在我的自定義annotationView重寫的drawRect,所以當我寫annotationView覆蓋drawRect中,阿爾法圖像

[[_mapView viewForAnnotation:annotation] setNeedsDisplay]; 

我的註解視圖將被重繪,我也不會刪除註釋和補充它再次。

,這裏是我的drawRect

- (void)drawRect:(CGRect)rect { 
    UIImage* theImage = nil; 
    if(_pinType == T_UNKNOWN) theImage = [UIImage imageNamed:@"imgU.png"]; 
    else theImage = [UIImage imageNamed:@"imgK.png"]; 
    [theImage drawInRect:rect]; 
} 

的問題是,我的圖片與α和阿爾法部分爲黑色。

所以也許有人知道這個解決方案或一些建議呢? 我讀了很多關於這個帖子,也使用核心圖形,但沒有找到解決方案..

在此先感謝!

回答

3

您是否希望此視圖部分透明並在其下顯示內容?如果是這樣,請使用[self setOpaque:NO]。不透明視圖的drawRect負責以完全不透明的顏色繪製矩形中的每個像素。

+0

非常感謝!就是這樣! – Lukas 2012-02-11 07:56:21

1

此功能對於iOS 5.0是正確的。當您使用iOS版本< 5.0時,您會將alpha部分設爲黑色。

嘗試使用另一種方法繪製圖像。我不知道你使用這個代碼。要嘗試使用:

UIImageView *image = [[UIImageView alloc] initWithImage: theImage]; 
image.opaque = NO; 
[self.view addSubview: image]; 
+0

我已經在iOS 5的設備上測試過這個,但它仍然不起作用。你提出的initWithImage給出了相同的結果。謝謝你提供。 – Lukas 2012-02-10 12:47:02

+0

要嘗試爲UIImageView設置參數不透明,image.opaque = YES/NO。 – alexmorhun 2012-02-10 13:06:39

+0

@Infoq非常感謝你,這是它,但羅布納皮爾是第一個,所以我要標記他的答案是正確的。感謝您的幫助! – Lukas 2012-02-11 07:57:30