[英]Move button Right to left animation iOS - swift
I am creating an application with some buttons in a view controller. 我在视图控制器中创建带有一些按钮的应用程序。 I want to add one animation like all the buttons are move from right to left. 我想添加一个动画,就像所有按钮都从右移到左一样。 But all my buttons are moving from left to right. 但是我所有的按钮都从左向右移动。 Here is my code. 这是我的代码。
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);
}
I am very new to ios development. 我对ios开发非常陌生。 Please someone help me to solve this issue. 请有人帮我解决这个问题。 Here b1_center_alignment, b2_center_alignment
are center horizontal constraints from storyboard
. 这里b1_center_alignment, b2_center_alignment
是storyboard
b1_center_alignment, b2_center_alignment
的中心水平约束。
When you do 当你做
b1_center_alignment.constant -= self.view.bounds.width;
You're hiding the button on the left side of the screen, and then with 您正在隐藏屏幕左侧的按钮,然后使用
self.b5_center_alignment.constant += self.view.bounds.width
you move it back to it's original position 您将其移回原始位置
You need to invert the signals 您需要反转信号
b1_center_alignment.constant += self.view.bounds.width;
and self.b5_center_alignment.constant -= self.view.bounds.width 和self.b5_center_alignment.constant-= self.view.bounds.width
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.