Xcode / Swift:动画奇怪的跳跃

时间:2016-07-29 09:32:18

标签: swift xcode animation

我在Swift中遇到一些奇怪的动画问题。当我做动画时,一切正常。但是当我添加另一个更改,例如同时添加文本时,动画会突然跳起来。

按下按钮1:没问题

按下按钮2:突然动画完全错误。为什么?

我无法弄清楚为什么会发生这种情况,以及如何处理它。该项目可以从我的网站下载:http://maartenm.nl/AnimationProblem.zip

import UIKit

class ViewController: UIViewController {



@IBOutlet weak var problemtxt: UILabel!
@IBOutlet weak var block: UIView!
@IBOutlet weak var button: UIButton!
@IBOutlet weak var buttontwo: UIButton!



@IBAction func buttonPressed(sender: UIButton) {
    UIView.animateWithDuration(Double(2.0), animations:
        {
            self.block.center = CGPointMake(self.block.center.x + 280 , self.block.center.y)
        }
        , completion: { (Bool)  in
            self.block.center = CGPointMake(self.block.center.x - 280 , self.block.center.y)
    } )
}



@IBAction func buttonTwoPressed(sender: UIButton) {
    self.problemtxt.text = "now what happens?"
    UIView.animateWithDuration(Double(2.0), animations:
        {
            self.block.center = CGPointMake(self.block.center.x + 280 , self.block.center.y)
        }
        , completion: { (Bool)  in
            self.block.center = CGPointMake(self.block.center.x - 280 , self.block.center.y)               
    } )
}

}

0 个答案:

没有答案