// 创建CAShapeLayer对象,并设置其路径
let shapeLayer = CAShapeLayer()
shapeLayer.strokeColor = UIColor.blue.cgColor
shapeLayer.lineWidth = 2.0
shapeLayer.fillColor = UIColor.clear.cgColor
kPManager.window.layer.addSublayer(shapeLayer)
// 创建CABasicAnimation对象,并设置其路径属性、持续时间等属性
let fromPath = UIBezierPath(arcCenter: CGPoint(x: 0, y: 300), radius: 10, startAngle: 0, endAngle: CGFloat(Double.pi * 2), clockwise: true)
let toPath = UIBezierPath(arcCenter: CGPoint(x: 400, y: 300), radius: 30, startAngle: 0, endAngle: CGFloat(Double.pi * 2), clockwise: true)
let animation = CABasicAnimation(keyPath: "path")
animation.duration = 2.0
animation.fromValue = fromPath.cgPath
animation.toValue = toPath.cgPath
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
// 将动画添加到CAShapeLayer对象中,并启动动画
shapeLayer.add(animation, forKey: "pathAnimation")
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
shapeLayer.removeFromSuperlayer()
}
网友评论