Keyboard Animation Curve as Int

uiview animation curve swift
uikeyboardanimationcurveuserinfokey
uikeyboardanimationdurationuserinfokey
uiview animation custom curve
uiviewanimationoptions
move uitextfield when keyboard appears swift 4
move view up when keyboard appears ios swift 4

I am trying to get the UIAnimationCurve of the keyboard, if it exists. The code I am using is below:

if let kbCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int{
                animateCurve = UIViewAnimationCurve.
            }

However, animateCurve, being a UIViewAnimationCurve, cannot be converted from an Int. How do I get the curve this way?

If I treat them as numbers, not UIViewAnimationCurve enums, the below errors when attempting to animate:

//Animated done button with keyboard
        origDoneFrame = btnDone.frame
        btnDone.hidden = false
        UIView.animateWithDuration(
            animateDuration,
            delay: Numbers.ANIMATE_DELAY,
            options: nil,
            animations: {
                UIView.setAnimationCurve(animateCurve)
                self.btnDone.frame = CGRectMake(self.btnDone.frame.origin.x + kbHeight, self.btnDone.frame.origin.y, self.btnDone.frame.size.width, self.btnDone.frame.size.height)
                return Void()
            },
            completion: {finished in
                return Void()
            }
        )

Is there a way to set the curve using an int?

Attempted int curve with:

UIView.animateWithDuration(
            animateDuration,
            delay: Numbers.ANIMATE_DELAY,
            options: UIViewAnimationOptions(animateCurve << 16),
            animations: {
                self.btnDone.frame = CGRectMake(self.btnDone.frame.origin.x + kbHeight, self.btnDone.frame.origin.y, self.btnDone.frame.size.width, self.btnDone.frame.size.height)
                return Void()
            },
            completion: {finished in
                return Void()
            }
        )

But compile error occurs due to UIViewAnimationOptions not being correct type. If I run the assignment of UIViewAnimationOptions on it's own, I get the compiler error "Could not find an overload for 'init' that accepts the supplied arguments."


You can get an enum value from the raw Int value with

animateCurve = UIViewAnimationCurve(rawValue: kbCurve)

However, the standard keyboard uses an animation curve value of 7, which might not match up with an enum value, so animateCurve would be nil. If this is the case, just define animateCurve as an Int and use the raw values in your code rather than the enum values.

Additionally, a quick Google search turned up this wrapper, which might be useful to you: https://gist.github.com/kristopherjohnson/13d5f18b0d56b0ea9242

Update to answer edited question:

You can use an integer animation curve value in the animation options by converting it to a UIViewAnimationOptions value:

UIViewAnimationOptions(kbCurve << 16)  // where kbCurve: UInt

Update for Swift 1.2 (XCode 6.3):

The release notes for Swift 1.2 indicate that NS_ENUM types with undocumented values can now be converted from their raw integer values without being reset to nil. So the following code will now work:

let animateCurve = UIViewAnimationCurve(rawValue: userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue)!

Update for Swift 2.2 (XCode 7.3):

if let animationCurveInt = (userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber)?.unsignedIntegerValue {
  let animationCurve = UIViewAnimationOptions(rawValue: animationCurveInt<<16)
  ...
}

Swift convenience wrapper for the userInfo values associated with a , :param: notification Keyboard-related notification. public init(_ Keyboard animation curve. ///. /// Note that public var animationCurve: Int {. It will only respond to key events when the component it is registered to is focusable AND has keyboard focus. The problem is, focus changes and it's a pain to manage and control. Instead, you should be using the Key Bindings API which was designed to help solve this problem


Swift 4 version:

if let curveValue = (userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue {
    let curveAnimationOptions = UIViewAnimationOptions(rawValue: curveValue << 16)
    //...
}

Sync animation to keyboard appearing · GitHub, userInfo. let animationCurve: Int = {. if let keyboardAnimationCurve = keyboardAnimationDetail?[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int {. This lets you clear, add or remove any keys from the array. If keys are not sorted by time, they will be automatically sorted on assignment. Note that the array is "by value", i.e. getting keys returns a copy of all keys and setting keys copies them into the curve.


You should use an older API, non-block based one. Then you will be able to set animation curve, which you will obtain from notification object.

Responding To Keyboard Events in iOS, Adjusting our app's UI when the keyboard is shown and dismissed is necessary to doubleValue, let animationCurve = (userInfo? integer value for a UIViewAnimationCurve , but UIView animations require a value of type  All keys defined in the animation curve. length: The number of keys in the curve. (Read Only) postWrapMode: The behaviour of the animation after the last keyframe. preWrapMode: The behaviour of the animation before the first keyframe. this[int] Retrieves the key at index. (Read Only)


Rig it Right!: Maya Animation Rigging Concepts, Maya Animation Rigging Concepts Tina O'Hailey. w-'Ell man 8mm w We are now going to add an IK handle from N ecklfINT to Neck7i INT. Select the Select the curve and with your cursor in the outliner hit f on the keyboard. This will frame​  The code above can reproduce the animation precisely. Once animation curve is set to the keyboard one, UIView animation will ignore the duration in the parameter. (If you really want to change the duration, adjust the mass value.)


Animating Around the iOS Keyboard - Atomic Spin, My recent post gave an introduction to iOS animation, showing how to Unfortunately, our text field gets covered up by the keyboard as soon as we tap it: doubleValue]; UIViewAnimationCurve animationCurve = [[userInfo  Assumptions are never a good idea, so I started doing some little testing and found out something that really surprised me: While AnimationCurve takes 10-30 times as long as Mathf.Lerp on the first call (but we're talking 0.1ms vs. 0.01ms, so it's not like a big thing in absolute numbers), when you go over several loops, it actually is a little


The Essential Guide to Processing for Flash Developers, void drawCurve(){ beginShape(); for (int i=0; i<vecs.length; i++){ In ActionScript​, to perform the simplest programmatic animation you might do such as listen for mouse and keyboard events while still performing standard program functions​. In this lesson we'll take a look at the power of animation curves in After Effects. Learn More About Animation Curves: https://www.schoolofmotion.com/tutoria