1
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)
}

首先,我点击开始按钮执行动画,它工作正常,但是当动画完成后,我再次点击开始按钮开始动画,它不起作用,并且没有调用动画块

4

0 回答 0