1
我創建了一個shaperLayer,並且圖層的路徑由bezierPath提供。代碼如下:UIView動畫使用SpringWithDamping
let shapeLayer = CAShapeLayer()
let bezierPath = UIBezierPath()
let bezierPath1 = UIBezierPath()
shapeLayer.fillColor = UIColor.cyan.cgColor
bezierPath.move(to: CGPoint.zero)
bezierPath.addLine(to: CGPoint(x: 0, y: 50))
bezierPath.addCurve(to: CGPoint(x: 140.935, y: 50), controlPoint1: CGPoint(x: 0, y: 50), controlPoint2: CGPoint(x: 87.340, y: 50))
bezierPath.addCurve(to: CGPoint(x: 250.578, y: 50), controlPoint1: CGPoint(x: 198.5, y: 50), controlPoint2: CGPoint(x: 250.578, y: 50))
bezierPath.addCurve(to: CGPoint(x: 375, y: 50), controlPoint1: CGPoint(x: 250.57, y: 50), controlPoint2: CGPoint(x: 299.064, y: 50))
bezierPath.addLine(to: CGPoint(x: 375, y: 0))
bezierPath.close()
bezierPath1.move(to: CGPoint.zero)
bezierPath1.addLine(to: CGPoint(x: 0, y: 81.5))
bezierPath1.addCurve(to: CGPoint(x: 140.935, y: 139.099), controlPoint1: CGPoint(x: 0, y: 81.5), controlPoint2: CGPoint(x: 87.340, y: 81.5))
bezierPath1.addCurve(to: CGPoint(x: 250.578, y: 139.09), controlPoint1: CGPoint(x: 198.5, y: 203.90), controlPoint2: CGPoint(x: 250.578, y: 139.09))
bezierPath1.addCurve(to: CGPoint(x: 375, y: 81.5), controlPoint1: CGPoint(x: 250.57, y: 139.09), controlPoint2: CGPoint(x: 299.064, y: 81.5))
bezierPath1.addLine(to: CGPoint(x: 375, y: 0))
bezierPath1.close()
shapeLayer.path = bezierPath1.cgPath
self.view.layer.addSublayer(shapeLayer)
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0, options: [], animations: {
shapeLayer.path = bezierPath.cgPath
}) { (finish) in
}
}
但動畫不是我想要的。我預期的效果是這樣的: good effect
實際效果是這樣的: real effect
我不知道爲什麼。它沒有反彈效果。我thik我錯過了重要的東西,有沒有人可以幫助我?