重新启动UIViewPropertyAnimation时不要再移动

时间:2018-11-29 03:49:12

标签: ios animation uiviewpropertyanimator

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

首先,我单击“开始”按钮执行动画,效果很好,但是动画结束后,我再次单击“开始”按钮以启动动画,它不起作用,并且没有调用动画块

0 个答案:

没有答案