我想創建一個簡單的示例,將圖像繪製到圖層,然後設置該圖層的alpha蒙版。我將下面的代碼添加到我的示例應用程序的viewDidLoad中。沒有設置面具,我可以看到葉子的圖像。在我設置面具之後,我看不到任何我的子層。我究竟做錯了什麼?CALayer alpha蒙版不工作
這裏有兩個圖像我使用(只樣本我在網上找到) http://sorenworlds.netfirms.com/Alpha/leaf.jpg
http://sorenworlds.netfirms.com/Alpha/leaf-alfa.jpg
self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
self.view.layer.cornerRadius = 20.0;
self.view.layer.frame = CGRectInset(self.view.layer.frame, 20, 20);
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.shadowOffset = CGSizeMake(0, 3);
sublayer.shadowRadius = 5.0;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 0.8;
sublayer.frame = CGRectMake(30, 30, 128, 192);
[self.view.layer addSublayer:sublayer];
CGImageRef img = [UIImage imageNamed:@"leaf.jpg"].CGImage;
sublayer.borderColor = [UIColor blackColor].CGColor;
sublayer.borderWidth = 2.0;
sublayer.contents = img;
CGImageRef imgAlpha = [UIImage imageNamed:@"leaf_alpha.jpg"].CGImage;
CALayer *alphaLayer = [CALayer layer];
alphaLayer.contents = (id)imgAlpha;
sublayer.mask = alphaLayer;
任何幫助是極大的讚賞。
感謝。 #1和3做的伎倆。感謝幫助。 – 2011-05-08 11:31:32