2015-07-21 55 views
3

我一個動畫文本框下面的代碼:設置選項斯威夫特2

UIView.animateWithDuration(0.5, delay: 0.4, 
     options: .Repeat | .Autoreverse | .CurveEaseOut, animations: { 
      self.password.center.x += self.view.bounds.width 
     }, completion: nil) 

我得到的錯誤Could not find member 'Repeat'

如果我設置只有一個選項的代碼纔有效。 爲什麼不讓我設置多個選項?

回答

9

的結合OptionSetType的語法已經改變,你將能夠做到這一點是這樣的:

UIView.animateWithDuration(0.5, delay: 0.4, 
    options: [.Repeat, .CurveEaseOut, .Autoreverse], animations: { 
     self.password.center.x += self.view.bounds.width 
    }, completion: nil) 
+1

太謝謝你了!你在哪裏找到這個? – MortalMan

+1

「UIViewAnimationOptions」的文檔顯示它符合'OptionSetType'協議。 「OptionSetType」的文檔在如何組合選項方面有一個很好的例子。您也可以在Xcode中通過命令單擊「UIViewAnimationOptions」,然後通過cmd單擊「OptionSetType」查看與文檔相同的示例代碼。 – simeon