Ios Swift 3按钮动画跳到右侧

Ios Swift 3按钮动画跳到右侧,ios,swift,animation,Ios,Swift,Animation,我已将此按钮设置为在单击时“反弹”的动画。它确实可以工作,但一旦动画完成,它就会跳到右侧,然后返回到它应该所在的位置。我认为最好是运行此代码(连接到一个按钮)自己查看。我正在iPad上测试我的应用程序。基本上,我想知道为什么它在动画制作之后马上跳到他身上。这是我的密码: @IBAction func randomiseButton(_ sender: Any) { if self.choices.isEmpty == true { let theButton = send

我已将此按钮设置为在单击时“反弹”的动画。它确实可以工作,但一旦动画完成,它就会跳到右侧,然后返回到它应该所在的位置。我认为最好是运行此代码(连接到一个按钮)自己查看。我正在iPad上测试我的应用程序。基本上,我想知道为什么它在动画制作之后马上跳到他身上。这是我的密码:

@IBAction func randomiseButton(_ sender: Any) {
    if self.choices.isEmpty == true {
        let theButton = sender as! UIButton
        let bounds = theButton.bounds
        UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: .curveEaseInOut, animations: {
            theButton.bounds = CGRect(x: bounds.origin.x - 20, y: bounds.origin.y, width: bounds.size.width + 60, height: bounds.size.height)
        }) { (success:Bool) in
            if success {
                UIView.animate(withDuration: 0.5, animations: {
                    theButton.bounds = bounds
                })
            }
        }
当在检查数组“choices”是否为空的第一个if语句之外时,也会发生这种情况


干杯,马特,好的,在问了这个问题10分钟后,我把代码搞乱了,我修改了最后一个动画

UIView.animate(withDuration: 0.5, 


不知道为什么,但这似乎奏效了

好吧,在问了这个问题10分钟后,我把代码搞乱了,我修改了最后一个动画

UIView.animate(withDuration: 0.5, 


不知道为什么,但这似乎奏效了

删除完成块

UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: .curveEaseInOut, animations: {
    theButton.bounds = CGRect(x: bounds.origin.x - 20, y: bounds.origin.y, width: bounds.size.width + 60, height: bounds.size.height)
})
附笔。 守则:

UIView.animate(withDuration: 0,

表示动画将在0秒内执行。

删除完成块

UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: .curveEaseInOut, animations: {
    theButton.bounds = CGRect(x: bounds.origin.x - 20, y: bounds.origin.y, width: bounds.size.width + 60, height: bounds.size.height)
})
附笔。 守则:

UIView.animate(withDuration: 0,
表示动画将在0秒内执行