2015-11-05 108 views
0

我正在使用視圖控制器中的一些按鈕創建應用程序。我想添加一個動畫,就像所有按鈕都是從右向左移動一樣。但是我所有的按鈕都是從左向右移動的。這是我的代碼。移動按鈕從右到左動畫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的中心水平約束。

+0

您是否試過' - ='而不是'+ ='? – keithbhunter

+0

你的意思是b1_center_alignment.constant + = self.view.bounds.width;在viewwill出現和self.b1_center_alignment.constant - = self.view.bounds.width這樣在viewdidappear權? – Amsheer

+0

是的。那樣有用嗎? – keithbhunter

回答

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

+0

我也認爲同樣的螞蟻試圖做你喜歡的答案,並且響應是從右向左移動的按鈕,但它沒有完成。問題最初是按鈕處於其原始位置,動畫移動到按鈕的頂部。 – Amsheer

+0

你明白我的意思嗎?如果不是,請告訴我,我會添加截圖 – Amsheer

+0

對不起,我不明白 – Leonardo