我想掩蓋一個UIView圖像使用它的圖層的蒙版屬性。我看到了無數的例子,說「這就是這麼簡單」。然而,經過相當多的調整後,我似乎無法重現所描述的結果。設置圖層蒙版只會使視圖消失。下面是我使用的代碼:CALayer蒙版不能正常工作
- (void)setMaskImage:(UIImage *)maskImage
{
_maskImage = maskImage;
self.layer.mask.contents = (__bridge id)(_maskImage.CGImage);
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self != nil) {
self.layer.mask = [CALayer layer];
}
return self;
}
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
self.layer.mask.frame = self.layer.bounds;
}
,這裏是我試圖用來掩蓋觀看圖片:http://cl.ly/0a300G2r133V
這是部分,但不完全是問題。 –