Reputation: 597
I want to draw a circle with animation, where the animation starts from 12 o'clock, and goes 360 degrees. Everything works fine, but I can not resize the circle.
If I use UIBezierPath - I can define the starting point ("startAngle: -CGFloat.pi / 2").
let shapeLayer = CAShapeLayer()
let center = progressView.center
let circularPath = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
shapeLayer.path = circularPath.cgPath
If I use UIBezierPath(ovalIn:...) I can resize.. But I want to use both, or how can I keep the start angle, and the size too?
shapeLayer.path = UIBezierPath(ovalIn: CGRect(x: 8, y: 78, width: 70, height: 70)).cgPath
Upvotes: 0
Views: 770
Reputation: 131511
For the first version of your path code, the radius parameter determines the size of the circle.
In the second version, it draws an oval (which may or may not be a circle) into a rectangular box.
Both let you control the size, just with different parameters.
If you want to vary the size of the arc drawn with init(arcCenter:radius:startAngle:endAngle:clockwise:)
then vary the radius parameter.
A circle drawn with
let circularPath = UIBezierPath(arcCenter: center,
radius: 100,
startAngle: -CGFloat.pi / 2,
endAngle: 2 * CGFloat.pi,
clockwise: true)
Will be twice as big as a circle drawn with
let circularPath = UIBezierPath(arcCenter: center,
radius: 50,
startAngle: -CGFloat.pi / 2,
endAngle: 2 * CGFloat.pi,
clockwise: true)
(And btw, if the start angle is -π/2, shouldn't the end angle be 3π/2, so the arc is 360° (or 2π) rather than 450°?)
Upvotes: 1