How to force raw value 7 to enumeration UIViewAnimationCurve?

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

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

It works great in Objective-C. Any idea how to get this animation curve from notification to UIView animation using Swift?


Update: As Martin noted, this is no longer an issue with Xcode 6.3.

From Xcode 6.3 Release Notes :

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

+6
source share
1 answer

I think I understood this, but I'm not sure that it should be done that way.

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


Update: The solution contained in this question also works.

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

Source: https://habr.com/ru/post/973450/


All Articles