将按钮从右向左移动动画iOS-swift

将按钮从右向左移动动画iOS-swift,ios,swift,ios-animations,Ios,Swift,Ios Animations,我正在用视图控制器中的一些按钮创建一个应用程序。我想添加一个动画,就像所有的按钮都是从右向左移动一样。但我所有的按钮都在从左向右移动。这是我的密码 override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) b1_center_alignment.constant -= self.view.bounds.width; b2_center_alignme

我正在用视图控制器中的一些按钮创建一个应用程序。我想添加一个动画,就像所有的按钮都是从右向左移动一样。但我所有的按钮都在从左向右移动。这是我的密码

 override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        b1_center_alignment.constant -= self.view.bounds.width;
        b2_center_alignment.constant -= self.view.bounds.width;
        b3_center_alignment.constant -= self.view.bounds.width;
        b4_center_alignment.constant -= self.view.bounds.width;
        b5_center_alignment.constant -= self.view.bounds.width;
}

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated);
        UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
            self.b5_center_alignment.constant += self.view.bounds.width
            self.view.layoutIfNeeded()
            }, completion: nil)

        UIView.animateWithDuration(0.5, delay: 0.3, options: UIViewAnimationOptions.CurveEaseOut, animations: {
            self.b4_center_alignment.constant += self.view.bounds.width
            self.view.layoutIfNeeded()
            }, completion: nil)


        UIView.animateWithDuration(0.5, delay: 0.6, options: UIViewAnimationOptions.CurveEaseOut, animations: {
            self.b3_center_alignment.constant += self.view.bounds.width
            self.view.layoutIfNeeded()
            }, completion: nil)
        UIView.animateWithDuration(0.5, delay: 0.9, options: UIViewAnimationOptions.CurveEaseOut, animations: {
            self.b2_center_alignment.constant += self.view.bounds.width
            self.view.layoutIfNeeded()
            }, completion: nil)

        UIView.animateWithDuration(0.5, delay: 1.2, options: UIViewAnimationOptions.CurveEaseOut, animations: {
            self.b1_center_alignment.constant += self.view.bounds.width
            self.view.layoutIfNeeded()
            }, completion: nil);

    }
我对ios开发非常陌生。请有人帮我解决这个问题。这里的
b1\u中心对齐、b2\u中心对齐
是执行此操作时来自
故事板的中心水平约束

b1_center_alignment.constant -= self.view.bounds.width;
您正在隐藏屏幕左侧的按钮,然后使用

self.b5_center_alignment.constant += self.view.bounds.width
你把它移回原来的位置

你需要反转信号

b1_center_alignment.constant += self.view.bounds.width;

self.b5_center_alignment.constant-=self.view.bounds.width

您是否尝试了
-=
而不是
+=
?您的意思是b1_center_alignment.constant+=self.view.bounds.width;将在视图中显示,并且像在视图中这样的self.b1_center_alignment.constant-=self.view.bounds.width显示对吗?是。这行吗?我也认为同样的蚂蚁尝试这样做,反应是按钮从右向左移动,但它没有完成。问题是最初按钮处于其原始位置,动画移动到按钮顶部。我还认为同一只蚂蚁会尝试按照您的答案进行操作,响应是按钮从右向左移动,但尚未完成。问题是最初按钮处于其原始位置,动画移动到按钮顶部。你明白我的意思吗?如果没有,请告诉我我会添加屏幕快照对不起,我不明白我发现了问题,但不知道如何解决。我的问题是我设置了按钮的前导空间,这就是问题所在。删除前导空格后,空格宽度将发生变化。有没有办法解决这个问题?谢谢,我解决了我的问题。我做的另一个修改是删除前导空格并添加尾随空格。一切都很完美。