PhotoTransitionsExample icon indicating copy to clipboard operation
PhotoTransitionsExample copied to clipboard

Use bit-shifting technique to produce animation curve suitable for use in block-based animation API

Open ericallam opened this issue 12 years ago • 0 comments

In iOS7, the animation of the keyboard show/hide changed. Its duration and, most notably, its curve is different from previous iOS versions. As before, if you want to animate something with the keyboard, you can listen to UIKeyboardWillShowNotification/UIKeyboardWillHideNotification and use the values from the userInfo dictionary to coordinate your animations with the keyboard. The userInfo dictionary contains the keyboard's begin frame, end frame, animation curve and animation duration.

However, in iOS 7, the animation curve is an undefined value, meaning that it is not one of the 4 defined values of UIViewAnimationCurve. Instead, its value is 7. This is a problem if you want to use the same curve in your own animation, because such a curve is not defined. The work-around, as discussed on the Apple forums, is to manually translate the UIViewAnimationCurve to a UIViewAnimationOptions value. From the definition of UIViewAnimationOptions, we learn that this translation is done by shifting the curve value 16 times to the left: option = curve << 16. This works great, but shouldn't be necessary. I hope Apple will add this mysterious 5th curve to the definitions in a future iOS update.

ericallam avatar Dec 30 '13 19:12 ericallam