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. Please someone help me to solve this issue. Here b1_center_alignment, b2_center_alignment
are center horizontal constraints from storyboard
.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.