我创建了一个半圆,根据我指定的值计算结束角度,这些值总是变化的。这一切都很完美,但问题是,当我测试应用程序时,我知道值已经更新但我需要大约40秒直到绘制半圆。如何让它看起来更快?
class Circle: UIView {
var muliplier: CGFloat = 1.0
var centerOfCircleView: CGPoint {
return CGPoint(x: bounds.midX, y: bounds.midY+40)
}
var halfOfViewsSize: CGFloat{
return min(bounds.size.height, bounds.size.width) / 2 * muliplier
}
var lineWidth: CGFloat = 25
// circles radius
var half = CGFloat.pi
var quarter = CGFloat(3 * CGFloat.pi / 2)
var endAngle: CGFloat = 0.0 {
didSet {
setNeedsDisplay()
}
}
override func draw(_ rect: CGRect) {
super.draw(rect)
self.drawCircleCenteredAtVariavel(center: centerOfCircleView, withRadius: halfOfViewsSize).stroke()
}
func drawCircleCenteredAtVariavel(center: CGPoint, withRadius radius: CGFloat) -> UIBezierPath {
let circlePath = UIBezierPath(arcCenter: centerOfCircleView, radius: halfOfViewsSize, startAngle: half, endAngle: endAngle , clockwise: true)
circlePath.lineWidth = lineWidth
return circlePath
}
}