微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

types – Swift:NSNumber不是UIViewAnimationCurve的子类型

我如何获得下面的行编译?

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 & fromRaw()

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))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐