The key UIKeyboardAnimationCurveUserInfoKey https://developer.apple.com/documentation/uikit/uiresponder/1621613-keyboardanimationcurveuserinfoke在 a 的 userInfo 字典中UIKeyboardWillShowNotification
包含一个Int
与价值7
.
现在我需要通过这个Int
into UIView.setAnimationCurve(<here>)
。我尝试像这样创建所需的 UIViewAnimationCurve 枚举UIViewAnimationCurve(rawValue: 7)
。因为原始值7
没有记录,结果总是nil
.
这种方式在 Objective-C 中工作得很好。知道如何使用 Swift 将通知中的动画曲线转换为 UIView 动画吗?
Update:正如 Martin 所指出的,自 Xcode 6.3 以来,这不再是问题。
来自Xcode 6.3 发行说明 https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW392:
进口NS_ENUM
具有未记录值的类型,例如UIViewAnimationCurve
,现在可以使用以下命令从原始整数值转换而来:init(rawValue:)
初始化器而不被重置为nil
。使用的代码unsafeBitCast
作为此问题的解决方法,可以编写为使用原始值初始值设定项。
我想我已经明白了,但我不确定这是否是应该的方式。
let animationCurve = unsafeBitCast(7, UIViewAnimationCurve.self)
UIView.setAnimationCurve(animationCurve)
Update:该解决方案包含在question https://stackoverflow.com/q/24041737/4097也有效。
var animationCurve = UIViewAnimationCurve.EaseInOut
NSNumber(integer: 7).getValue(&animationCurve)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)