我正在使用視圖控制器中的一些按鈕創建應用程序。我想添加一個動畫,就像所有按鈕都是從右向左移動一樣。但是我所有的按鈕都是從左向右移動的。這是我的代碼。移動按鈕從右到左動畫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
的中心水平約束。
您是否試過' - ='而不是'+ ='? – keithbhunter
你的意思是b1_center_alignment.constant + = self.view.bounds.width;在viewwill出現和self.b1_center_alignment.constant - = self.view.bounds.width這樣在viewdidappear權? – Amsheer
是的。那樣有用嗎? – keithbhunter