After many experiments, I found the best answer to my own question. A short answer is change frame when you get UIKeyboardDidHideNotification
.
Custom inputView is embedded in another view controlled by the system called UIPeripheralHostView
.
So changing the custom inputView at wrong time is not reflected immediately or shows an ugly layout at best.
When the device rotates, the system briefly hides the keyboard, then performs a rotation animation of the keyboard from old orientation to new orientation. I think the animation block is inserted somewhere between two notifications UIKeyboardDidHideNotification
and UIKeyboardWillShowNotification
. These notifications are coupled with UIKeyboardWillChangeFrameNotification
. The "frame" in this notification actually means the frame of UIPeripheralHostView
.
So changing the frame of my input view when I get UIKeyboardDidHideNotification
gives the system a chance to adjust the frame of UIPeripheralHostView
before the animation starts, resulting in smooth transition from short keyboard to tall keyboard during orientation change.
This works in iOS 5. But Apple may change the practice in the future.