3

Very strange iOS 8 bug.

  • My iOS app has some UIViewControllers with UITextfields
  • When in edit mode, they needed extra help dismissing the keyboard when tapping outside
  • I fixed this in iOS 7 by adding something like this in each VC

    - (void)keyboardWasShown:(NSNotification*)notification
    {
        id responder = [UIResponder currentFirstResponder];
        if ([responder isKindOfClass:[UITextField class]]) {
            _textFieldResponder = responder;
        }
        else {
            _textFieldResponder = nil;
        }
    }
    
    - (void)keyboardWillHide:(NSNotification*)notification
    {
        _textFieldResponder = nil;
    }
    
    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event usualReturn:(BOOL)rv
    {
        if (_textFieldResponder) {
            CGPoint pvIn = [_textFieldResponder convertPoint:point fromView:self.view];
            if (!CGRectContainsPoint(_textFieldResponder.bounds, pvIn)) {
                [UIResponder resignAnyFirstResponder];
            }
        }
        return rv;
    }
    

and in viewDidLoad of the VCs

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

This has worked great in iOS 7. Now in iOS 8, this also works fine...

UNTIL!

It works fine until the user 4-finger swipes off to a different application and then comes back. Then when the uitextfield goes into edit mode, tapping the keyboard will send the touch straight through to the UIVew behind it, triggering pointInside and causing the keyboard to dismiss.

Can you please help me understand what in the world happens (in iOS 8) when leaving the application that would cause this to behave so strangely? Thank you so much for your help.

Kevin
  • 16,696
  • 7
  • 51
  • 68
roro
  • 265
  • 3
  • 11

0 Answers0