3

I have this issue only for iOS8. Everything works properly on iOS7.

My view configuration:

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

My test procedure:

  1. Tap the UIView subclass. The custom keyboard is shown.
  2. Tap a special key on the inputView, which makes the UITextView become the first responder. The alpha keyboard is shown.
  3. After typing text into the UITextView, tap on the UIView subclass again to make it first responder. The alpha keyboard disappears, and the custom keyboard reappears.
  4. Click the home button to exit to the home screen. Tap the app icon to resume the app.

The bug is that when the app resumes, the inputView is no longer visible, whereas it was just before step #4. Tapping on the UIView subclass does not bring it back. isFirstResponder returns true for the UIView subclass if I check it after step #4.

Any idea how to keep my inputView from disappearing?

jeremywhuff
  • 2,911
  • 3
  • 29
  • 33
  • Or ideas for a reasonable work-around. – i_am_jorf Nov 12 '14 at 18:22
  • 1
    I have a suggestion to improve the question and help the quality of answers. Build a simple one-view example that demonstrates the issue, put it on github, and post the link here. There is no downside to doing this. If you can show the problem in a simple example, fixing and/or identifying the issue is a million times easier and provides less guesswork. If you can't reproduce it, then you know that the cause is something external to the situation you described above. – mattr Nov 13 '14 at 13:37

2 Answers2

3

This is definitely an iOS bug.

inputView posts keyboard notifications same as the regular keyboard. In this case, UIKeyboardWillHideNotification is being called for MainView's inputView on app foreground even though MainView is still the first responder.

A cleaner fix to this issue would be to register for UIKeyboardWillHideNotification on MainView and reset firstResponder status.

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

Handle the buggy trigger.

func handleKeyboardWillHideNotification(notification:NSNotification) {
    if (self.isFirstResponder())
    {
        self.resignFirstResponder()
        self.becomeFirstResponder()
    }
}
Krys Jurgowski
  • 2,871
  • 17
  • 25
0

I have posted an example project that demonstrates the bug and a fix for it here: https://github.com/jeremywhuff/HWInputViewBugExample

Run it on iOS8, and you'll see the bug. Run it on iOS7, and you won't.

I've added a "hack fix" switch, which will demonstrate the fix. Definitely not ideal, but it's the best I can come up with. It causes keyboards to flicker on the simulator, but during device tests, this does not seem to happen.

The hack fix can be found in 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 resign first responder, which appears to kick the system out of its invisible inputView mode.

jeremywhuff
  • 2,911
  • 3
  • 29
  • 33
  • Hey thanks for the example, this will really help. Generally, you shouldn't use an answer to clarify a question. You should just edit your question and add the details there: http://stackoverflow.com/help/editing. Also, I get a crash on iOS 7.1 Simulator: https://www.dropbox.com/s/gb3ebkjivkq7sx4/Screenshot%202014-11-13%2013.58.07.png?dl=0 on step #2. But I will take a look, thanks! – mattr Nov 13 '14 at 19:08
  • I just pushed the fix to the crash. I don't think I clarified the question in this answer, I only suggested a solution, correct? – jeremywhuff Nov 13 '14 at 19:26
  • I see it as: you are the OP and providing additional information about the original question. I dont see this as a solution but if you consider it a solution to your question then you are correct. – mattr Nov 13 '14 at 19:30
  • Edited my response to make my solution more obvious (doesn't require digging through the project to find) – jeremywhuff Nov 13 '14 at 19:34
  • ahh ok that makes more sense now :) – mattr Nov 13 '14 at 19:39