Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIKeyboardWillChangeFrameNotification UIViewAnimationCurve set to 7 on iOS 7

Tags:

ios

uikeyboard

I am looking to determine how the keyboard will animate in. On iOS 6 I get a valid value for the UIKeyboardAnimationCurveUserInfoKey (which should be a UIViewAnimationCurve with a value from 0-3) but the function returns a value of 7. How does the keyboard animate in? What can be done with the value of 7?

NSConcreteNotification 0xc472900 {name = UIKeyboardWillChangeFrameNotification; userInfo = {
    UIKeyboardAnimationCurveUserInfoKey = 7;
    UIKeyboardAnimationDurationUserInfoKey = "0.25";
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}";
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}";
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";
    UIKeyboardFrameChangedByUserInteraction = 0;
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";
}}
like image 689
madmik3 Avatar asked Oct 20 '13 20:10

madmik3


2 Answers

It seems that the keyboard is using an undocumented/unknown animation curve.

But you can still use it. To convert it to a UIViewAnimationOptions for block animations shift it by 16 bits like so

UIViewAnimationCurve keyboardTransitionAnimationCurve;
[[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey]
                           getValue:&keyboardTransitionAnimationCurve];

keyboardTransitionAnimationCurve |= keyboardTransitionAnimationCurve<<16;

[UIView animateWithDuration:0.5
                  delay:0.0
                options:keyboardTransitionAnimationCurve
             animations:^{
                // ... do stuff here
           } completion:NULL];

Or just pass it in as an animation curve.

UIViewAnimationCurve keyboardTransitionAnimationCurve;
[[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey]
                           getValue:&keyboardTransitionAnimationCurve];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:keyboardTransitionAnimationCurve];
// ... do stuff here
[UIView commitAnimations];
like image 178
madmik3 Avatar answered Oct 17 '22 09:10

madmik3


I can't comment unfortunately otherwise I would instead of entering a new answer.

You can also use:

animationOptions |= animationCurve << 16;

This may be preferred as it will retain previous OR = operations on the animationOptions.

like image 23
Chris Berry Avatar answered Oct 17 '22 09:10

Chris Berry