从右到左移动按钮动画 iOS - swift
Move button Right to left animation iOS - swift
我正在用视图控制器中的一些按钮创建一个应用程序。我想添加一个动画,就像所有按钮都从右向左移动一样。但是我所有的按钮都从左向右移动。这是我的代码。
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
.
的中心水平约束
当你
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
我正在用视图控制器中的一些按钮创建一个应用程序。我想添加一个动画,就像所有按钮都从右向左移动一样。但是我所有的按钮都从左向右移动。这是我的代码。
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
.
当你
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