【发布时间】:2015-11-28 05:26:29
【问题描述】:
我制作 CAShapeLayer 的代码是
UIBezierPath *circle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(75, 125)
radius:50
startAngle:0
endAngle:1.8 * M_PI
clockwise:YES];
CAShapeLayer *circleLayer = [CAShapeLayer layer];
[circleLayer setFrame:CGRectMake(200 - 50, 300 - 50, 100, 100)];
circleLayer.path = circle.CGPath;
circleLayer.bounds = CGPathGetBoundingBox(circle.CGPath);
circleLayer.strokeColor = [UIColor colorWithRed:0.4 green:1.0 blue:0.2 alpha:0.5].CGColor;
[circleLayer setFillColor:[UIColor clearColor].CGColor];
circleLayer.lineWidth = 3.0;
if ([circleLayer animationForKey:@"SpinAnimation"] == nil) {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: 2 * M_PI];
animation.duration = 2.0f;
animation.repeatCount = INFINITY;
animation.removedOnCompletion = NO;
[circleLayer addAnimation:animation forKey:@"SpinAnimation"];
}
[self.view.layer addSublayer:circleLayer];
我想制作 CAGradientLayer 而不是 CAShapeLayer。
原因:我需要在图层中使用渐变色,这在 CAShapeLayer 中是不可能的。
我想在 Cirle 上使用黄色到黑色的渐变。
图片:
在我需要的输出中,颜色是从背景图像中获取的,并在末尾添加一些黑色,或者在图层中添加不透明度 0。
任何想法,建议。
谢谢。
【问题讨论】:
-
视图的背景颜色是否固定?我的意思是,背景颜色是你已经知道的某种颜色(比如白色)。
-
是的,View的背景颜色是固定的@ChengYuHsu
标签: ios cashapelayer cagradientlayer