While implementing a system to determine which text input widget has focus, and place it in the right location when the keyboard shows up, I have found some odd and inconsistent behavior in the calling of the ui.View keyboard_frame_will_change() and keyboard_frame_did_change() methods. I'm curious if anyone else is seeing anything like this?
First, it seems like they get called much more often than I'd expect when the keyboard shows up or hides or changes size. I was expecting a call to "keyboard_frame_will_change()" just before the keyboard shows or changes size, and then a call to "keyboard_frame_did_change()" just after it has finished showing or changing size.
Instead, I see at least two calls to "will change" and then two calls to "did change" all with the same keyboard frame on my iPad, but on my iPhone 7, I'm seeing even more: two "will change" calls with one frame size, then two "did change" with that same size, then another set of two calls each to "will change" and "did change" with a somewhat different size, then another set of two calls each to "will change" and "did change" back to the first frame size.
Also, on my iPhone, but not on the iPad, I see when I run my app in one orientation and then rotate to the other (so, from portrait to landscape or vice versa) and then tap a text field and bring up a keyboard, the reported frame size is either for the wrong orientation, or is invalid (0,0,0,0).
Below I'm including the debugging output I get if I just print the "frame" parameter that "keyboard_frame_will_change()" and "keyboard_frame_did_change()" are given. For each it's just a single tap in a textfield, and the keyboard coming up:
iPad, landscape orientation:
keyboard frame will change: (0.00, 370.00, 1024.00, 398.00)
keyboard frame will change: (0.00, 370.00, 1024.00, 398.00)
keyboard frame did change: (0.00, 370.00, 1024.00, 398.00)
keyboard frame did change: (0.00, 370.00, 1024.00, 398.00)
iPad, portrait orientation:
keyboard frame will change: (0.00, 711.00, 768.00, 313.00)
keyboard frame will change: (0.00, 711.00, 768.00, 313.00)
keyboard frame will change: (0.00, 711.00, 768.00, 313.00)
keyboard frame will change: (0.00, 711.00, 768.00, 313.00)
keyboard frame did change: (0.00, 711.00, 768.00, 313.00)
keyboard frame did change: (0.00, 711.00, 768.00, 313.00)
keyboard frame did change: (0.00, 711.00, 768.00, 313.00)
keyboard frame did change: (0.00, 711.00, 768.00, 313.00)
iPhone, portrait orientation:
keyboard frame will change: (0.00, 409.00, 375.00, 258.00)
keyboard frame will change: (0.00, 409.00, 375.00, 258.00)
keyboard frame did change: (0.00, 409.00, 375.00, 258.00)
keyboard frame did change: (0.00, 409.00, 375.00, 258.00)
keyboard frame will change: (0.00, 451.00, 375.00, 216.00)
keyboard frame will change: (0.00, 451.00, 375.00, 216.00)
keyboard frame did change: (0.00, 451.00, 375.00, 216.00)
keyboard frame did change: (0.00, 451.00, 375.00, 216.00)
keyboard frame will change: (0.00, 409.00, 375.00, 258.00)
keyboard frame will change: (0.00, 409.00, 375.00, 258.00)
keyboard frame did change: (0.00, 409.00, 375.00, 258.00)
keyboard frame did change: (0.00, 409.00, 375.00, 258.00)
iPhone, landscape orientation:
keyboard frame will change: (0.00, 181.00, 667.00, 194.00)
keyboard frame will change: (0.00, 181.00, 667.00, 194.00)
keyboard frame did change: (0.00, 181.00, 667.00, 194.00)
keyboard frame did change: (0.00, 181.00, 667.00, 194.00)
keyboard frame will change: (0.00, 213.00, 667.00, 162.00)
keyboard frame will change: (0.00, 213.00, 667.00, 162.00)
keyboard frame did change: (0.00, 213.00, 667.00, 162.00)
keyboard frame did change: (0.00, 213.00, 667.00, 162.00)
keyboard frame will change: (0.00, 181.00, 667.00, 194.00)
keyboard frame will change: (0.00, 181.00, 667.00, 194.00)
keyboard frame did change: (0.00, 181.00, 667.00, 194.00)
keyboard frame did change: (0.00, 181.00, 667.00, 194.00)
iPhone orientation change (Portrait to Landscape):
keyboard frame will change: (0.00, 409.00, 375.00, 258.00)
keyboard frame will change: (0.00, 409.00, 375.00, 258.00)
keyboard frame did change: (0.00, 409.00, 375.00, 258.00)
keyboard frame did change: (0.00, 409.00, 375.00, 258.00)
keyboard frame will change: (0.00, 451.00, 375.00, 216.00)
keyboard frame will change: (0.00, 451.00, 375.00, 216.00)
keyboard frame did change: (0.00, 451.00, 375.00, 216.00)
keyboard frame did change: (0.00, 451.00, 375.00, 216.00)
keyboard frame will change: (0.00, 409.00, 375.00, 258.00)
keyboard frame will change: (0.00, 409.00, 375.00, 258.00)
keyboard frame did change: (0.00, 409.00, 375.00, 258.00)
keyboard frame did change: (0.00, 409.00, 375.00, 258.00)
keyboard frame will change: (0.00, 0.00, 0.00, 0.00)
keyboard frame will change: (0.00, 0.00, 0.00, 0.00)
keyboard frame did change: (0.00, 0.00, 0.00, 0.00)
keyboard frame did change: (0.00, 0.00, 0.00, 0.00)
keyboard frame will change: (0.00, 181.00, 375.00, 194.00)
keyboard frame will change: (0.00, 181.00, 375.00, 194.00)
keyboard frame did change: (0.00, 181.00, 375.00, 194.00)
keyboard frame did change: (0.00, 181.00, 375.00, 194.00)
keyboard frame will change: (0.00, 181.00, 375.00, 194.00)
keyboard frame will change: (0.00, 181.00, 375.00, 194.00)
keyboard frame did change: (0.00, 181.00, 375.00, 194.00)
keyboard frame did change: (0.00, 181.00, 375.00, 194.00)
For all the above, this is python2.7, and the iPad is running iOS 11.4.1 and the iPhone is running 12.0.1