Commit 84c0780e25b7be43a71229845dd2d390133b57ce

Sam Lantinga 2016-12-02T02:21:35

Fixed bug 3305 - Fixed TextInput status when the keyboard was dismissed with the dismiss key on the iPad Diego I was previously unaware that rotating the device to a different orientation when the keyboard is shown causes a keyboardWillHide followed by a keyboardWillShow notification. The previous patch would then mistakenly StopTextInput when rotating. This patch fixes that by checking if the device is rotating before stopping text input.

diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m
index e6e903e..80bd66f 100644
--- a/src/video/uikit/SDL_uikitviewcontroller.m
+++ b/src/video/uikit/SDL_uikitviewcontroller.m
@@ -58,6 +58,7 @@ SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char 
 
 #if SDL_IPHONE_KEYBOARD
     UITextField *textField;
+    BOOL rotatingOrientation;
 #endif
 }
 
@@ -70,6 +71,7 @@ SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char 
 
 #if SDL_IPHONE_KEYBOARD
         [self initKeyboard];
+        rotatingOrientation = FALSE;
 #endif
 
 #if TARGET_OS_TV
@@ -211,6 +213,29 @@ SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char 
     }
 }
 
+/* willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation are deprecated in iOS 8+ in favor of viewWillTransitionToSize */
+#if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
+{
+    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
+    rotatingOrientation = TRUE;
+    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
+                                 completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
+                                     rotatingOrientation = FALSE;
+                                 }];
+}
+#else
+- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
+    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
+    rotatingOrientation = TRUE;
+}
+
+- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
+    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
+    rotatingOrientation = FALSE;
+}
+#endif /* TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000 */
+
 - (void)deinitKeyboard
 {
 #if !TARGET_OS_TV
@@ -251,7 +276,8 @@ SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char 
 
 - (void)keyboardWillHide:(NSNotification *)notification
 {
-    SDL_StopTextInput();
+    if (!rotatingOrientation)
+        SDL_StopTextInput();
     [self setKeyboardHeight:0];
 }