iOS 7 - Keyboard animation

I'm trying to understand the new keyboard animation in iOS 7.0 on the iPhone 5 Simulator. I want to resize my UITableView when the keyboard appears, but I can't get the right animation details. I'm using the information from the NSNotification object, when the keyboard appears or disappears.

Here is my log:

Move keyboard from {{0, 920}, {320, 216}} to {{0, 352}, {320, 216}}
 with duration: 0.400000
 and animation curve: 7

UIViewAnimationCurveEaseInOut = 0
UIViewAnimationCurveEaseIn = 1
UIViewAnimationCurveEaseOut = 2
UIViewAnimationCurveLinear = 3

The animation curve is an unknown value, what should I do?

In iOS 7, the keyboard uses a new, undocumented animation curve. While some have noted that using an undocumented value for the animation option, I prefer to use the following:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
[UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]];
[UIView setAnimationBeginsFromCurrentState:YES];

// work

[UIView commitAnimations];

While block based animations are the recommendation, the animation curve returned from the keyboard notification is an UIViewAnimationCurve, while the option you would need to pass to block based animations is an UIViewAnimationOptions. Using the traditional UIView animation methods allows you to pipe the value directly in. Most importantly, this will use the new undocumented animation curve (integer value of 7) and cause the animation to match the keyboard. And, it will work just as well on iOS 6 and 7.

iOS 7, I'm trying to understand the new keyboard animation in iOS 7.0 on the iPhone 5 Simulator. I want to resize my UITableView when the keyboard appears, but I� ‎Read reviews, compare customer ratings, see screenshots, and learn more about GIF Emoji Keyboard - New 5000 + Animated 3D Emoticons Keyboard for iOS 8 & iOS 7 FREE. Download GIF Emoji Keyboard - New 5000 + Animated 3D Emoticons Keyboard for iOS 8 & iOS 7 FREE and enjoy it on your iPhone, iPad, and iPod touch.

Now I found the solution. The animation starts from the point {0, 920} to {0, 352}. The problem was that the UITableView object started with a size of {160, 568}, so I changed the size of the UITableView to {160, 920} before the animation was started.

Concerning to the unknown animation curve, I just set the parameter to animationCurve << 16 to convert it from a view animation curve to a view animation option. The value is not equal to the linear, ease in, ease out and ease inout animation curve.

Here is my code:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(_keyboardWillShow:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

and:

- (void)keyboardWillShow:(NSNotification *)aNotification {
    NSDictionary *userInfo = aNotification.userInfo;

    //
    // Get keyboard size.

    NSValue *beginFrameValue = userInfo[UIKeyboardFrameBeginUserInfoKey];
    CGRect keyboardBeginFrame = [self.view convertRect:beginFrameValue.CGRectValue fromView:nil];

    NSValue *endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardEndFrame = [self.view convertRect:endFrameValue.CGRectValue fromView:nil];

    //
    // Get keyboard animation.

    NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration = durationValue.doubleValue;

    NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
    UIViewAnimationCurve animationCurve = curveValue.intValue;

    //
    // Create animation.

    CGRect tableViewFrame = self.tableView.frame;
    bTableViewFrame.size.height = (keyboardBeginFrame.origin.y - tableViewFrame.origin.y);
    self.tableView.frame = tableViewFrame;

    void (^animations)() = ^() {
        CGRect tableViewFrame = self.tableView.frame;
        tableViewFrame.size.height = (keyboardEndFrame.origin.y - tableViewFrame.origin.y);
        self.tableView.frame = tableViewFrame;
    };

    //
    // Begin animation.

    [UIView animateWithDuration:animationDuration
                          delay:0.0
                        options:(animationCurve << 16)
                     animations:animations
                     completion:nil];
}

iOS 7 - Keyboard animation - objective-c - javascript, I'm trying to understand the new keyboard animation in iOS 7.0 on the iPhone 5 Simulator. I want to resize my UITableView when the keyboard appears, but I� It's generally accepted that iOS 7.1 managed to vastly improve on the speed, timings and effects that make up various animations within the firmware. Thankfully, those who prefer to remain jailbroken on an earlier version of iOS 7.0.x can now replicate those animations by following a few simple steps.

You can use animateWithDuration block and set curve inside it. It's clean and work well.

UIViewAnimationCurve curve = [[notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];

[UIView animateWithDuration:duration
                    delay:0
                  options:UIViewAnimationOptionBeginFromCurrentState 
               animations:^{
                 [UIView setAnimationCurve:curve];
                 /* ANIMATION HERE */
                 // don't forget layoutIfNeeded if you use autolayout
               }
               completion:nil];

Happy coding!

UPDATE

You can use a simple UIViewController category written by me https://github.com/Just-/UIViewController-KeyboardAnimation

GIF Emoji Keyboard PRO, Download GIF Emoji Keyboard PRO - New 5000 + Animated 3D Emoticons Keyboard for iOS 8 & iOS 7 and enjoy it on your iPhone, iPad, and iPod touch. Before the keyboard pops up, figure out: – How tall it’s going to be, – How long its animation will take, and – What type of animation curve it will use. Right as the keyboard animation starts, launch an animation that moves our controls up exactly as the keyboard moves up (or down).

Use UIKeyboardWillChangeFrameNotification instead, because some international keyboards, like the Chinese keyboard, change height during use. Also this code gives you the correct heights for the keyboard, even in landscape mode. (Note: the code below is for Autolayout)

//set your observer, in a method like viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];

- (void)keyboardWillChange:(NSNotification *)notification {
    CGRect initialRect = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
    CGFloat initialHeight = self.view.frame.size.height - [self.view convertRect:initialRect fromView:nil].origin.y;
    CGRect keyboardRect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat newHeight = self.view.frame.size.height - [self.view convertRect:keyboardRect fromView:nil].origin.y;
    //set your constraints here, based on initialHeight and newHeight, which are the heights of the keyboard before & after animation.
    [self.contentView setNeedsUpdateConstraints];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
    [UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [self.contentView layoutIfNeeded];
    [UIView commitAnimations];
}

Keyboard animation and text input, keyboard animation on older version of iOS. Keyboard animation and text input . How to mimic Keyboard animation on iOS 7 to add "Done" button to numeric. *Also works with iPads and iPods Touch* *Also works with iOS 5 and iOS 6* How to Enable Emoji Keyboard in iOS 7 Open Settings Go to "General" Scroll down and tap "Keyboard" Select "Keyboards" Tap

To use the same animation as keyboard has, you have to use undocumented Curve option.

- (void)keyboardWillHide:(NSNotification *)notification {
    NSDictionary *userInfo = [notification userInfo];

    CGRect rect = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    NSTimeInterval animationDuration = [[userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    NSInteger curve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue] << 16;

    [UIView animateWithDuration:animationDuration delay:0.0 options:curve animations:^{

    } completion:nil];
}

I found that actually method animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion: is the new way that all animations are done in iOS7 and iOS8 now. You just make right duration, damping and velocity and you will get the same effect, but even you can change speed/time.

CLIPish Keyboard on the App Store, Download CLIPish Keyboard and enjoy it on your iPhone, iPad, and iPod touch. This app is available only on the App Store for iPhone and iPad. GIF Emoji Keyboard PRO - New 5000 + Animated 3D Emoticons Keyboard for iOS 8 & iOS 7. Showing You Apple's new iOS7 on The iPad ! The new animations look great & gives the new iOS a great natural feel ! Subscribe For Lots More iOS7 Videos !

How to mimic Keyboard animation on iOS 7 to add “Done” button to , I had been doing something like this to mimic the keyboard animation on older version of iOS. CGRect keyboardBeginFrame;; [[note.userInfo� Re: iOS Keyboard show animation curve control points Level 1 (0 points) jpdery Jun 6, 2016 7:20 AM ( in response to jpdery )

Position observing input accessory view to allow animation with , Position observing input accessory view to allow animation with interactive keyboard dismissal. Works in iOS 7 and 8. SSObservingInputAccessoryView.h. iOS 7 includes a lot of great, transitional animations, including all the Home screen icons coming out of warp space in staggered formation when you unlock. Same with the zooming in and out of the stacked planes of icons and folders and Home screens and apps.

Use IOS7 Keyboard Animation � Issue #188 � jessesquires , I'm sorry, I'm not really setup for PRs, but I wanted to share this change in keyboard animations. It looks really slick. It's easy to incorporate. All i need is ClassicFolders, ClassicBanners and a animation tweak to transform my device to iOS 6. I was so stupid i decided to go back to iOS 6 on the day when apple stopped signing iOS 6. I had to suffer with the slow animations and lag of iOS 7. Also don't update your A5 device to iOS 8! (until iOS 8.1)

Comments
  • check if this solves your problem stackoverflow.com/questions/11313951/…
  • Sorry, I forgot to write that I'm using a UIViewController with a UITableView subview.
  • What animation details are you expecting?
  • @Krishnan not a 7, I imagine.
  • Works perfectly on UIKeyboardWillShowNotification, but when dismissing the keyboard via UIKeyboardWillHideNotification my UIView seems to be out of sync with the keyboard.
  • is it legal to use an undocumented animation curve? Will Apple reject your app if you do this?
  • 1) This is likely to never be caught by Apple, but in general it would be a bad idea to use it directly. 2) We aren't using it directly here. We are naively passing the value we are given.
  • @Piotr I've discovered than in iOS 7, when the keyboard is performing the dismiss animation, it uses the undocumented UIViewAnimationCurve with integer value of 6 instead of the value of 7 that is reported by UIKeyboardAnimationCurveUserInfoKey. It's a hacky solution, but using [UIView setAnimationCurve:6] if the keyboard is dismissing seems to keep the UIView animation in sync.
  • I'd spent ages trying to get something to animate along with they keyboard properly and it never looked right until I found this answer. Thanks!
  • "Concerning to the unknown animation curve, I just set the parameter to animationCurve << 16 to convert it from a view animation curve to a view animation option." How did you come about this?
  • see the definition of UIViewAnimationOptionCurveEaseIn for example in UIView.h
  • Things like this are insanely frustrating. What the hell, Apple? Thanks.
  • Clean. The swift version is here stackoverflow.com/questions/24923086/…