我正在尝试在ca形状图层上添加渐变,如果我通过添加masklayer使用它,则它只会在当前视图框架上提供渐变效果,但它不会单独影响每个图层
这是我的代码:
CAShapeLayer *gradientMask = [CAShapeLayer layer];
gradientMask.fillColor = [[UIColor clearColor] CGColor];
gradientMask.strokeColor = [[UIColor blackColor] CGColor];
gradientMask.lineWidth = _borderStrokeWidth;
gradientMask.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
gradientMask.path = maskLayer.path;
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.8f],
[NSNumber numberWithFloat:1.0f],
nil];
gradientLayer.startPoint = CGPointMake(0.5,1.0);
gradientLayer.endPoint = CGPointMake(1.0,0.5);
gradientLayer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
NSArray *colors = [NSArray arrayWithObjects:(id)[UIColor redColor].CGColor, (id)[UIColor greenColor].CGColor,(id)[UIColor blueColor].CGColor,(id)[UIColor yellowColor].CGColor, nil];
gradientLayer.colors = colors;
[gradientLayer setMask:gradientMask];
// [gradientLayer setMask:shapeLayer];
[self.layer addSublayer:gradientLayer];
请提出建议