我想獲得鍵盤的UIAnimationCurve,如果存在的話。我使用的代碼如下:鍵盤動畫曲線爲真
if let kbCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int{
animateCurve = UIViewAnimationCurve.
}
然而,animateCurve,作爲一個UIViewAnimationCurve,不能從一個Int轉換。我如何通過這種方式獲得曲線?
如果我把他們當作數字,而不是UIViewAnimationCurve枚舉,下面的錯誤,當試圖動畫:
//Animated done button with keyboard
origDoneFrame = btnDone.frame
btnDone.hidden = false
UIView.animateWithDuration(
animateDuration,
delay: Numbers.ANIMATE_DELAY,
options: nil,
animations: {
UIView.setAnimationCurve(animateCurve)
self.btnDone.frame = CGRectMake(self.btnDone.frame.origin.x + kbHeight, self.btnDone.frame.origin.y, self.btnDone.frame.size.width, self.btnDone.frame.size.height)
return Void()
},
completion: {finished in
return Void()
}
)
有沒有一種方法來設置使用一個int曲線?
企圖INT曲線:
UIView.animateWithDuration(
animateDuration,
delay: Numbers.ANIMATE_DELAY,
options: UIViewAnimationOptions(animateCurve << 16),
animations: {
self.btnDone.frame = CGRectMake(self.btnDone.frame.origin.x + kbHeight, self.btnDone.frame.origin.y, self.btnDone.frame.size.width, self.btnDone.frame.size.height)
return Void()
},
completion: {finished in
return Void()
}
)
但是編譯錯誤的發生是由於UIViewAnimationOptions不是正確的類型。如果我自己運行UIViewAnimationOptions的賦值,那麼會出現編譯器錯誤「無法找到接受提供參數的'init'的重載。」
您是否嘗試過使用'as?而不是UIViewAnimationCurve'? – 2014-11-14 21:33:49
@IanMacDonald不能編譯。這個錯誤是不能預見的,因爲我已經注意到XCode經常出現這種情況,但是7與枚舉不匹配(參見下面的nickgraef的回覆) – steventnorris 2014-11-14 21:51:32