We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2212

Summary: SDL_SetTextInputRect has no effect on iOS
Product: SDL Reporter: philhassey <phil>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: amaranth72, icculus, phil
Version: 2.0.1Keywords: triage-2.0.4
Hardware: ARM   
OS: iOS 6   
Attachments: Patch to implement SDL_SteTextInputRect for uikit/iOS.
Patch to add iOS 8 support for SDL_SetTextInputRect

Description philhassey 2013-11-06 15:50:50 UTC
Overview: While SDL_SetTextInputRect works perfectly to move my window out of the way of the virtual keyboard using SDL2/Android, on iOS this function has no effect.

Steps to Reproduce: Call SDL_SetTextInputRect with a rect near the bottom of the screen before calling SDL_StartTextInput. 

Actual Results: The iOS virtual keyboard is displayed after calling SDL_StartTextInput, but the screen is not shifted to reveal the TextInputRect region.

Expected Results: The screen should be shifted to reveal the TextInputRect region (like with SDL2/Android.)

Build Date & Hardware: SDL 2.0.1, iOS 6.1.3, iPad 3rd Gen.

Additional Builds and Platforms: Don't know.

Additional Information: I was able to workaround this bug in my own code by using iOS calls to get the height of the virtual keyboard when it was displayed and shifting my own screen.  I would prefer if this was part of SDL2 though.  

To find the height of the screen you must addObservers for UIKeyboardWillShowNotification and UIKeyboardDidHideNotification. From the former, you can get the height/width of the keyboard using UIKeyboardFrameBeginUserInfoKey. Then pick height or width based on statusBarOrientation. Finally you must multiply by the mainScreen scale.
Comment 1 Sam Lantinga 2013-11-11 01:22:29 UTC
I'm not sure how we'd do this on iOS.  Any ideas?
Comment 2 philhassey 2013-11-11 17:43:01 UTC
Created attachment 1417 [details]
Patch to implement SDL_SteTextInputRect for uikit/iOS.

This patch implements SDL_SetTextInputRect for uikit/iOS.

It sets up notification handlers to respond to changes in the display of the keyboard.  These handlers then change the frame of the view so it is moved out of the way of the keyboard as per SetTextInputRect.
Comment 3 Sam Lantinga 2013-11-12 04:51:45 UTC
Great work, thanks!
https://hg.libsdl.org/SDL/rev/e4d2f3375868
Comment 4 philhassey 2015-02-24 17:07:20 UTC
Created attachment 2050 [details]
Patch to add iOS 8 support for SDL_SetTextInputRect

I've updated this patch to add support for iOS 8.  iOS 8 changed how coordinate systems worked, so the keyboard was opening improperly on all iOS 8 devices.

-Phil
Comment 5 philhassey 2015-02-24 17:09:57 UTC
I've re-opened this issue because my original patch only worked for iOS <= 7.  This patch now supports 7 and 8.
Comment 6 Alex Szpakowski 2015-02-24 19:44:08 UTC
My large iOS improvement patch (https://bugzilla.libsdl.org/show_bug.cgi?id=2798) also contains a fix for this on iOS 8+.
Comment 7 Ryan C. Gordon 2015-04-10 02:44:59 UTC
This bug should be fixed by the changes made for Bug #2798. Please reopen if that's not the case.

Thanks!

--ryan.