我正在尝试制作this progressbar
除了百分比标签外,我已经完成了所有操作,这些标签应与CAShapelayer的中间对齐并为其设置动画。
fileprivate func makeTheProgress() {
let center = middleView.center
shapeLayer.lineWidth = 16
let trackLayer = CAShapeLayer()
trackLayer.lineWidth = 16
let progressview = UIBezierPath(arcCenter: center, radius: 100, startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
//making track layer
trackLayer.path = progressview.cgPath
trackLayer.strokeColor = #colorLiteral(red: 1, green: 0.3098039216, blue: 0.6039215686, alpha: 1)
trackLayer.strokeEnd = 1
trackLayer.fillColor = UIColor.clear.cgColor
view.layer.addSublayer(trackLayer)
//making progress Layer
shapeLayer.path = progressview.cgPath
shapeLayer.strokeColor = #colorLiteral(red: 0, green: 0.8039215686, blue: 0.9843137255, alpha: 1)
shapeLayer.strokeEnd = 0
shapeLayer.fillColor = UIColor.clear.cgColor
view.layer.addSublayer(shapeLayer)
}
func animateProgress(){
let animation = CABasicAnimation(keyPath: "strokeEnd")
if totalCount == 0 {
animation.toValue = 1
}else{
animation.toValue = rightCount / totalCount
}
animation.duration = 1.5
animation.fillMode = CAMediaTimingFillMode.forwards
animation.isRemovedOnCompletion = false
shapeLayer.add(animation, forKey: "progressAnimation")
}
我正在尝试添加一个CATextLayer并对其进行动画处理,还有更好的方法吗?!