【发布时间】:2015-01-12 09:10:43
【问题描述】:
我正在尝试获取键盘的 UIAnimationCurve(如果存在)。我使用的代码如下:
if let kbCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int{
animateCurve = UIViewAnimationCurve.
}
但是,作为 UIViewAnimationCurve 的 animateCurve 不能从 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代替吗? -
@IanMacDonald 那不会编译。该错误与实际问题无关(我注意到 XCode 经常出现这种情况,但 7 与枚举不匹配(请参阅下面 nickgraef 的回复)
标签: ios swift keyboard uiviewanimation uiviewanimation-curve