9

Using NSNumber from NSNotification.userInfo[UIKeyboardAnimationCurveUserInfoKey]

In Objective C I would do the following

 [UIView animateWithDuration:1.0
                      delay:0
                    options:(curveValue.intValue << 16)

Swift will not allow me to do the same even though the bitshift operator is the same. I would like to get the enum raw value which is equivalent

UIViewAnimationOptionCurveEaseInOut = 0 << 16,

UIViewAnimationOptionCurveEaseIn = 1 << 16,

UIViewAnimationOptionCurveEaseOut = 2 << 16,

UIViewAnimationOptionCurveLinear = 3 << 16,

update


I am not sure if the below approach is correct , it seems to work

 var animationCurve : UIViewAnimationOptions = UIViewAnimationOptions.CurveEaseOut
 info[UIKeyboardAnimationCurveUserInfoKey].getValue(&animationCurve)


 UIView.animateWithDuration(durationValue.doubleValue,
        delay: 0,
        options: animationCurve,
        animations: {self.navigationController.toolbar.frame = myRect},
        completion: nil)
Ryan Heitner
  • 13,119
  • 6
  • 77
  • 119

4 Answers4

3

In Beta-5

UIViewAnimationOptions.fromRaw(
    UInt(
        ( p.userInfo[ UIKeyboardAnimationCurveUserInfoKey ] as NSNumber ).unsignedIntValue << 16
    )
)!
Satachito
  • 5,838
  • 36
  • 43
1

You have to init a UIViewAnimationOptions with the rawValue like this:

UIView.animateWithDuration(1.0, delay: 0, options: UIViewAnimationOptions.init(rawValue:UInt(curveValue.intValue << 16)),

n6xej
  • 461
  • 5
  • 15
-1

Is this what you need?

UIViewAnimationCurve.fromRaw(Int(hereGoesYourStuff))
Fernando Mazzon
  • 3,562
  • 1
  • 19
  • 21
  • Thanks for your answer, it may we be a solution but it is not quite complete. I think I may have resolved this – Ryan Heitner Jun 05 '14 at 09:00
  • 8
    Since the value of UIKeyboardAnimationCurveUserInfoKey is 7 which is not documented in the sdk, UIViewAnimationCurve.fromRaw(7) will return nil – ZYiOS Jul 30 '14 at 07:59
-1
let animationKey = userInfo[UIKeyboardAnimationCurveUserInfoKey] as UInt
UIViewAnimationOptions(rawValue: animationKey)
ChikabuZ
  • 10,031
  • 5
  • 63
  • 86
  • 1
    if animationKey is not 0-3, the init method returns nil which is incorrect since animationKey is 7 on ios 7+ – Kevlar Jan 03 '15 at 18:31