Fixed bug 3305 - Fixed TextInput status when the keyboard was dismissed with the dismiss key on the iPad
authorSam Lantinga <slouken@libsdl.org>
Fri, 02 Dec 2016 02:21:35 -0800
changeset 106715ecf0b24da52
parent 10670 bb7d3a4f58b0
child 10672 10fb0ebc4fbf
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.
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Thu Dec 01 07:31:08 2016 -0800
     1.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Fri Dec 02 02:21:35 2016 -0800
     1.3 @@ -58,6 +58,7 @@
     1.4  
     1.5  #if SDL_IPHONE_KEYBOARD
     1.6      UITextField *textField;
     1.7 +    BOOL rotatingOrientation;
     1.8  #endif
     1.9  }
    1.10  
    1.11 @@ -70,6 +71,7 @@
    1.12  
    1.13  #if SDL_IPHONE_KEYBOARD
    1.14          [self initKeyboard];
    1.15 +        rotatingOrientation = FALSE;
    1.16  #endif
    1.17  
    1.18  #if TARGET_OS_TV
    1.19 @@ -211,6 +213,29 @@
    1.20      }
    1.21  }
    1.22  
    1.23 +/* willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation are deprecated in iOS 8+ in favor of viewWillTransitionToSize */
    1.24 +#if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
    1.25 +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
    1.26 +{
    1.27 +    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    1.28 +    rotatingOrientation = TRUE;
    1.29 +    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
    1.30 +                                 completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
    1.31 +                                     rotatingOrientation = FALSE;
    1.32 +                                 }];
    1.33 +}
    1.34 +#else
    1.35 +- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    1.36 +    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    1.37 +    rotatingOrientation = TRUE;
    1.38 +}
    1.39 +
    1.40 +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    1.41 +    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    1.42 +    rotatingOrientation = FALSE;
    1.43 +}
    1.44 +#endif /* TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000 */
    1.45 +
    1.46  - (void)deinitKeyboard
    1.47  {
    1.48  #if !TARGET_OS_TV
    1.49 @@ -251,7 +276,8 @@
    1.50  
    1.51  - (void)keyboardWillHide:(NSNotification *)notification
    1.52  {
    1.53 -    SDL_StopTextInput();
    1.54 +    if (!rotatingOrientation)
    1.55 +        SDL_StopTextInput();
    1.56      [self setKeyboardHeight:0];
    1.57  }
    1.58