types – Swift:NSNumber不是UIViewAnimationCurve的子类型
发布时间:2020-12-14 04:51:31 所属栏目:百科 来源:网络整理
导读:我如何获得下面的行编译? UIView.setAnimationCurve(userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue) 现在,它给出了编译错误: 'NSNumber' is not a subtype of 'UIViewAnimationCurve' 为什么当integerValue被声明为Int时,编译器认为userInf
我如何获得下面的行编译?
UIView.setAnimationCurve(userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue) 现在,它给出了编译错误: 'NSNumber' is not a subtype of 'UIViewAnimationCurve' 为什么当integerValue被声明为Int时,编译器认为userInfo [UIKeyboardAnimationCurveUserInfoKey] .integerValue是一个NSNumber? class NSNumber : NSValue { // ... var integerValue: Int { get }`? // ... } 我与其他枚举类型有类似的问题.什么是一般解决方案? 解决方法UIView.setAnimationCurve(UIViewAnimationCurve.fromRaw(userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue)!) 阅读更多:Swift enumerations & UPDATE 基于this answer to How to use the default iOS7 UIAnimation curve,我使用新的基于块的动画方法animateWithDuration:delay:options:animations:completion:,并获取UIViewAnimationOptions,如下所示: let options = UIViewAnimationOptions(UInt((userInfo[UIKeyboardAnimationCurveUserInfoKey] as NSNumber).integerValue << 16)) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |