0

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

 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_center_alignment, b2_center_alignment是来自 的中心水平约束storyboard

4

1 回答 1

2

当你这样做

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

于 2015-11-05T13:27:55.263 回答