2012-03-13 78 views
2

我使用Quartz繪製在自定義的UIView說:「畫」如何使圖紙上完全透明視圖中可見

我有控制器視圖「viewC」

我做

[self.view addSubView:somePaintInstance]; in my viewC at some event 

現在,當我繪畫或繪畫時,Paint的默認背景爲「黑色」。

我想做一個完全透明畫/繪畫對我的「viewC」視圖

的頂部,所以我做

somePaintInstance.alpha=0.5; (before adding it as subview) 

但是,這也讓我的畫/畫透明與油漆的背景,所以,如果我還能保持完全透明的(alpha = 0.0),我看不出畫本身帶有油漆的觀點

我想什麼,而不是工作:

  • somePaintInstance.setbackgroundcolor
  • somePaintInstance.opaque

其他網站上的答案也是這樣執行的

我通過搶看答案這裏就不具體: How to add a transparent gradient mask to a context

但仍然不清楚我如何實現我想要的?

讓我知道其他細節,如果需要

問候,

+0

我也想知道如何完成上述。 – Zolomon 2012-06-13 09:04:30

回答

0

此行應該工作,

somePaintInstance.backGroundColor = [UIColor clearColor]; 
+0

已嘗試不工作 – user300940 2012-03-13 07:58:22

+0

@ user300940確保您的alpha = 1.0 ?.這對我有效。 – Vignesh 2012-03-13 08:03:14

+0

backGroundColor屬性在這種情況下根本不起作用,無論我把它放在哪裏,我都覺得需要一些Quartz特定的函數調用,這將允許背景上下文在繪製(上下文)的同時將完全透明。不是。 – user300940 2012-03-13 08:03:56

2

我試圖設置與alpha值0背景或與StartTransparentLayer工作。沒有任何工作。 對我而言有效的是將視圖不透明屬性設置爲NO。 在我看來的初始化我把以下代碼:

-(id)initWithFrame:(CGRect)frame { 
    if (self = [super initWithFrame:frame]) { 
     // set default values 
     self.colorNormal = [UIHelper ricolaYellow]; 
     self.colorActice = [UIColor colorWithHexString:CIRCLE_COLOR_ACTIVE]; 
     self.capacities = nil; 
     self.opaque = NO; 
    } 
    return self; 
}