UIKeyboardFrameBeginUserInfoKey & UIKeyboardFrameEndUserInfoKey

The start frame is where the keyboard is at the beginning of the animation: offscreen if the keyboard is being shown, or onscreen if the keyboard is being hidden. The end frame is where the keyboard will be at the end of the animation: vice versa. You can use the difference between them to write a single method that responds to both hiding and showing the keyboard.

Be sure also to use UIKeyboardAnimationCurveUserInfoKey and UIKeyboardAnimationDurationUserInfoKey when animating your view changes: that way, your animations and the OS’s animations will be in sync.

Another hint: The documentation you linked to states, “The rectangle contained in the UIKeyboardFrameBeginUserInfoKey and UIKeyboardFrameEndUserInfoKey properties of the userInfo dictionary should be used only for the size information it contains. Do not use the origin of the rectangle (which is always {0.0, 0.0}) in rectangle-intersection operations”. At least on the iPad on OS 3.2, this is not true. Both rects have the same size, while the origin, which is in screen coordinates, differs between the two.

You may find this question helpful: UIKeyboardBoundsUserInfoKey is deprecated, what to use instead?

Leave a Comment