IOS8 - UIView inputView disappears after application resumes

I only have this problem for iOS8. Everything works correctly on iOS7.

My view config:

  • I have a UIView subclass that has a custom inputView (custom keyboard)
  • The UIView subclass has a gesture recognizer that makes it the first responder when used
  • UIView subclass contains UITextView subview

My test procedure:

  • Tap on the UIView subclass. The custom keyboard is displayed.
  • Touch the special key on the inputView, which makes the UITextView the first to respond. The alpha keyboard is displayed.
  • After entering text in the UITextView, tap the UIView subclass again to make it the first responder. The alpha keyboard disappears and the custom keyboard reappears.
  • Press the "Home" button to exit to the main screen. Click the app icon to resume the app.

The error is that when the application resumes, the inputView is no longer displayed, whereas it was just before step # 4. Touching the UIView subclass does not return it. isFirstResponder returns true for the UIView subclass if I check it after step 4.

Any idea how to keep my input view from disappearing?

+3


source to share


2 answers


This is definitely an iOS bug.

inputView

publishes keyboard notifications, the same as regular keyboard. In this case, it is UIKeyboardWillHideNotification

called for MainView

inputView

in the foreground of the application, although MainView

it is still the first responder.

A cleaner solution to this problem would be registering to UIKeyboardWillHideNotification

on MainView

and reset the status of the firstResponder.



NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleKeyboardWillHideNotification:", name: UIKeyboardWillHideNotification, object: nil)

      

Process the buggy trigger.

func handleKeyboardWillHideNotification(notification:NSNotification) {
    if (self.isFirstResponder())
    {
        self.resignFirstResponder()
        self.becomeFirstResponder()
    }
}

      

+2


source


I posted a sample project demonstrating the error and fix for it here: https://github.com/jeremywhuff/HWInputViewBugExample

Run it on iOS8 and you will see an error. Run it on iOS7 and you won't.

I've added a "hack fix" radio button to demonstrate the fix. Definitely not perfect, but this is the best I can think of. This causes the keys on the simulator to blink, but during device testing this doesn't seem to happen.



The hack fix can be found at applicationDidBecomeActive:

mainView.textView!.becomeFirstResponder()
NSTimer.scheduledTimerWithTimeInterval(0.05, target: mainView.textView!, selector: "resignFirstResponder", userInfo: nil, repeats: false)

      

This causes the text view to become and then quickly override the first responder, which appears to push the system out of its invisible input mode.

0


source







All Articles