1
我試圖在UIImageView上添加一個遮罩層。該imageview保存圖像,遮罩層通過設置其內容來保存另一個圖像。但是,當我將遮罩層添加到imageview層時,遮罩層不包含任何圖像。掩模圖層已由getter初始化。添加遮罩層的方法如下:如何設置由UIBezierPath成形的CAShapeLayer的內容
- (void)circleButtonClicked{
self.maskLayer.contents = (id)[UIImage imageNamed:@"mask.jpg"].CGImage;
self.maskLayer.frame = CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_WIDTH);
self.maskLayer.opacity = 0.5;
[self.imageView.layer addSublayer:self.maskLayer];
UIBezierPath * pPath = [UIBezierPath bezierPathWithArcCenter:self.imageView.center radius:(kSCREEN_WIDTH-100)/2 startAngle:0.0 endAngle:M_PI*2 clockwise:YES];
self.maskLayer.path = pPath.CGPath;
UIBezierPath * otherPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_WIDTH)];
self.maskLayer.path = otherPath.CGPath;
[otherPath appendPath:pPath];
self.maskLayer.path = otherPath.CGPath;
self.maskLayer.fillRule = kCAFillRuleEvenOdd;
}