https://www.jianshu.com/p/3f21e81e09dd
https://www.jianshu.com/p/3f21e81e09dd
duration
isRemovedOnCompletion
autoreverses
repeatCount
HUGE
fillMode
keyTimes
calculationMode
添加上计算模式属性,让动画更平滑
values
path
六. CASpringAnimation(弹簧动画)
let redView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
redView.backgroundColor = .red
redView.center = view.center
view.addSubview(redView)
let animation = CASpringAnimation(keyPath: "transform.scale")
animation.beginTime = CACurrentMediaTime() + 3
animation.mass = 0.1 //设置质量,质量越大,惯性越大
animation.damping = 1//设置阻尼系数,阻尼系数越大,停止越快
animation.stiffness = 100 //设置刚性系数,刚性系数越大,运动越快
animation.initialVelocity = 0.3 //初始速率
animation.toValue = 2.0
animation.isRemovedOnCompletion = false
animation.repeatCount = HUGE
animation.autoreverses = true
animation.fillMode = .forwards
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
animation.duration = animation.settlingDuration//设置动画时长
redView.layer.add(animation, forKey: "scale")
image.png
网友评论