如何将原始值7强制为UIViewAnimationCurve枚举? [英] How to force a raw value of 7 into a UIViewAnimationCurve enum?

查看:256
本文介绍了如何将原始值7强制为UIViewAnimationCurve枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIKeyboardWillShowNotification 的用户信息字典中的键$ UIKeyboardAnimationCurveUserInfoKey 包含一个 Int $ 7

The key UIKeyboardAnimationCurveUserInfoKey in the userInfo dictionary of a UIKeyboardWillShowNotification contains an Int with the value 7.

现在我需要传递这个 Int into UIView.setAnimationCurve(< here>)。我试图用这个 UIViewAnimationCurve(rawValue:7)创建所需的UIViewAnimationCurve枚举。因为原始值 7 没有记录,所以结果总是 nil

Now I need to pass this Int into UIView.setAnimationCurve(<here>). I tried to create the required UIViewAnimationCurve enum like this UIViewAnimationCurve(rawValue: 7). Because the raw value 7 is undocumented, the result is always nil.

在Objective-C中,这样工作正常。任何想法如何将该动画曲线从通知转换成使用Swift的UIView动画?

It works fine this way in Objective-C. Any idea how to get this animation curve from the notification into a UIView animation using Swift?



更新: As Martin指出,自从Xcode 6.3开始,这不再是一个问题。


Update: As pointed out by Martin, this is no longer a problem since Xcode 6.3.

Xcode 6.3发行说明

现在可以使用init(rawValue :)初始化程序从原始整数值转换带有未记录值的导入的NS_ENUM类型,例如UIViewAnimationCurve,而不会重置为nil。使用unsafeBitCast作为此问题的解决方法的代码可以写入使用原始值初始化器。

Imported NS_ENUM types with undocumented values, such as UIViewAnimationCurve, can now be converted from their raw integer values using the init(rawValue:) initializer without being reset to nil. Code that used unsafeBitCast as a workaround for this issue can be written to use the raw value initializer.


推荐答案

我想我想出来了,但我不知道这是否应该是这样做的。

I think I figured it out, but I'm not sure if this is the way it's supposed to be done.

let animationCurve = unsafeBitCast(7, UIViewAnimationCurve.self)
UIView.setAnimationCurve(animationCurve)



更新:质询也是如此。

var animationCurve = UIViewAnimationCurve.EaseInOut
NSNumber(integer: 7).getValue(&animationCurve)

这篇关于如何将原始值7强制为UIViewAnimationCurve枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆