将NSNotification.userInfo [UIKeyboardAnimationCurveUserInfoKey]转换为Enum [英] Convert NSNotification.userInfo[UIKeyboardAnimationCurveUserInfoKey] to Enum
问题描述
使用NSNotification.userInfo中的NSNumber [UIKeyboardAnimationCurveUserInfoKey]
Using NSNumber from NSNotification.userInfo[UIKeyboardAnimationCurveUserInfoKey]
在目标CI中将执行以下操作
In Objective C I would do the following
[UIView animateWithDuration:1.0
delay:0
options:(curveValue.intValue << 16)
即使bitshift运算符相同,Swift也不允许我这样做。我想得到相当的枚举原始值
Swift will not allow me to do the same even though the bitshift operator is the same. I would like to get the enum raw value which is equivalent
UIViewAnimationOptionCurveEaseInOut = 0<< 16,
UIViewAnimationOptionCurveEaseInOut = 0 << 16,
UIViewAnimationOptionCurveEaseIn = 1<< 16,
UIViewAnimationOptionCurveEaseIn = 1 << 16,
UIViewAnimationOptionCurveEaseOut = 2<< 16,
UIViewAnimationOptionCurveEaseOut = 2 << 16,
UIViewAnimationOptionCurveLinear = 3<< 16,
UIViewAnimationOptionCurveLinear = 3 << 16,
更新
我不确定是否下面的方法是正确的,它似乎工作
I am not sure if the below approach is correct , it seems to work
var animationCurve : UIViewAnimationOptions = UIViewAnimationOptions.CurveEaseOut
info[UIKeyboardAnimationCurveUserInfoKey].getValue(&animationCurve)
UIView.animateWithDuration(durationValue.doubleValue,
delay: 0,
options: animationCurve,
animations: {self.navigationController.toolbar.frame = myRect},
completion: nil)
推荐答案
在Beta-5中
UIViewAnimationOptions.fromRaw(
UInt(
( p.userInfo[ UIKeyboardAnimationCurveUserInfoKey ] as NSNumber ).unsignedIntValue << 16
)
)!
这篇关于将NSNotification.userInfo [UIKeyboardAnimationCurveUserInfoKey]转换为Enum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!