Change user input height when turning the device

I created a custom keyboard view and associated it with the inputView property of UITextField. Is there a way to change the height of a custom inputView when changing orientation and smoothly changing an animated frame in the same way as the system keyboard? My keyboard size is 768x272, and when the device goes to the album, the size becomes 1024x272, but I want to make it larger as 1024x372. If I changed the frame with the code below when I get UIDeviceOrientationDidChangeNotification, the animation of the changes is not smooth.

textField.inputView.frame = CGRectMake(0,0,1024,372); 
+6
source share
2 answers

Per Apple Documentation for UIResponder.inputView: "If UIKit encounters an input view with a UIViewAutoresizingFlexibleHeight value in the autoresist mask, it changes the height corresponding to the keyboard."

So, if you want to adjust the height, you should not specify the UIVieAutoresizingFlexibleHeight mask.

+6
source

After many experiments, I found the best answer to my question. The short answer is a change frame when you get a UIKeyboardDidHideNotification .

A custom inputView is embedded in another view managed by a system called UIPeripheralHostView . Therefore, changing a custom inputView at the wrong time does not immediately reflect or show an ugly layout at best.

When the device rotates, the system briefly hides the keyboard, and then animates the rotation of the keyboard from the old orientation to the new orientation. I think an animation block is inserted somewhere between the two notifications UIKeyboardDidHideNotification and UIKeyboardWillShowNotification . These notifications are associated with the UIKeyboardWillChangeFrameNotification . β€œRam” in this notification actually means a UIPeripheralHostView frame.

Thus, changing the scope of my input view when I receive UIKeyboardDidHideNotification gives the system the ability to adjust the frame of the UIPeripheralHostView before starting the animation, which will lead to a smooth transition from the short keyboard to the high keyboard during orientation changes.

This works in iOS 5. But Apple may change the practice in the future.

+2
source

Source: https://habr.com/ru/post/920390/


All Articles