【发布时间】:2018-05-31 07:34:37
【问题描述】:
我正在尝试画一个圆圈,但无论我设置什么值,圆圈边框总是一样薄。 感觉就像总是默认最细宽度的线。
- (void)drawCircleAtPoint:(CGPoint)center radius: (CGFloat)radius{
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineWidth = 4; // Here
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineJoinRound;
CGFloat r = radius;
[path addArcWithCenter:center radius:r startAngle:0.0 endAngle:M_PI*2 clockwise:true];
[path stroke];
CAShapeLayer* layer = [CAShapeLayer new];
layer.path = path.CGPath;
layer.strokeColor = UIColor.redColor.CGColor;
layer.fillColor = UIColor.yellowColor.CGColor;
[layer addAnimation:[self getAnimation] forKey:nil];
[self.layer addSublayer:layer];
}
- (CABasicAnimation*)getAnimation {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.duration = 1.2;
animation.fromValue = @0;
animation.toValue = @1;
return animation;
}
这真的把我逼疯了。
【问题讨论】:
-
您在层中而不是在贝塞尔路径中设置线宽总是让我感到非常奇怪!
-
值得注意的是,这同样适用于端盖形状等
标签: ios objective-c core-graphics core-animation uibezierpath