Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode/Swift:动画奇怪的跳跃_Swift_Xcode_Animation - Fatal编程技术网

Xcode/Swift:动画奇怪的跳跃

Xcode/Swift:动画奇怪的跳跃,swift,xcode,animation,Swift,Xcode,Animation,我在Swift的动画中遇到了一些奇怪的问题。当我只做动画时,一切都很好。但当我添加另一个更改时,例如同时添加一个文本,动画会突然跳转 按按钮1:没问题 按下按钮2:突然,动画完全错误。为什么? 我不明白为什么会发生这种情况,以及该怎么办。该项目可从我的网站下载: }当您使用autolayout时,您应该设置块约束的动画,而不是中心。那么a)为什么它在Button1中工作?和b)如何设置约束动画?和c)文本更改与动画有什么关系??它在“animateWithDuration”命令之外!因为更新标签

我在Swift的动画中遇到了一些奇怪的问题。当我只做动画时,一切都很好。但当我添加另一个更改时,例如同时添加一个文本,动画会突然跳转

按按钮1:没问题

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

我不明白为什么会发生这种情况,以及该怎么办。该项目可从我的网站下载:


}

当您使用autolayout时,您应该设置块约束的动画,而不是中心。那么a)为什么它在Button1中工作?和b)如何设置约束动画?和c)文本更改与动画有什么关系??它在“animateWithDuration”命令之外!因为更新标签文本时,视图约束将重新计算。这会干扰帧动画。搜索如何设置NSLayoutConstraints的动画。对不起,不是这样。我试图在没有约束的情况下重新制作整个场景,但在我开始制作动画的那一刻,每个图像都会在屏幕上跳跃,这是不需要的。当你使用自动布局时,你应该为块的约束而不是中心设置动画。那么a)为什么它在Button1中工作?和b)如何设置约束动画?和c)文本更改与动画有什么关系??它在“animateWithDuration”命令之外!因为更新标签文本时,视图约束将重新计算。这会干扰帧动画。搜索如何设置NSLayoutConstraints的动画。对不起,不是这样。我试图不受限制地重拍整个场景,但在我开始制作动画的那一刻,每个图像都在屏幕上跳跃,这是不必要的。
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)               
    } )
}