override func viewDidLoad() {
super.viewDidLoad()
animator = UIViewPropertyAnimator(duration: 10, curve: .linear, animations: {
var frame = self.button.frame
frame.origin.y = frame.origin.y + 100
self.button.frame = frame
})
animator?.addCompletion({ (position) in
print(self.animator?.state.des, position.des)
})
}
@IBAction func start(_ sender: Any) {
animator?.startAnimation()
}
@IBAction func pause(_ sender: Any) {
animator?.pauseAnimation()
}
@IBAction func stop(_ sender: Any) {
//animator?.stopAnimation(true)
animator?.stopAnimation(false)
animator?.finishAnimation(at: .current)
}
首先,我单击“开始”按钮执行动画,效果很好,但是动画结束后,我再次单击“开始”按钮以启动动画,它不起作用,并且没有调用动画块