我想获得键盘的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