1

I'm working on a custom keyboard for iOS which will have its own search field (similarly implemented by PopKey).

My keyboard's textfield is able to take the focus with becomeFirstResponder and I'm able to give it up by using resignFirstResponder. However after I resign focus, the host app has a difficult time retaking focus despite touching the form. The app's textfield will still show the text cursor blinking.

Any ideas? Thanks

user339946
  • 5,961
  • 9
  • 52
  • 97

1 Answers1

6

The solution is a hack, as of right now you can't really give the host app its focus back.

  • Subclass a UITextField and on its delegate implement textFieldShouldBeginEditing by returning NO.

  • Add a BOOL property isSelected that gets set to YES in touchesBegan (not to be confused with the default selected property)

  • In your keyboard's keyPressed method, if searchField.isSelected, manipulate the searchField.text. Else, manipulate textDocumentProxy like normal.
  • Add a clear button and method that wipes searchField.text and searchField.isSelected, allowing any further keystrokes to return to the textDocumentProxy
  • Add an animation that replicates the blinking type cursor
user339946
  • 5,961
  • 9
  • 52
  • 97