1

Is it possible to disable the keyboard from showing when a webpage element is selected inside a UIWebView?

Jordan Smith
  • 10,310
  • 7
  • 68
  • 114
user281300
  • 1,427
  • 2
  • 19
  • 31

1 Answers1

1

Register for a keyboard notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

And then you can stop it from showing by placing the following code in keyboardWillShow :

UITextField *dummyTextField = etc. 
//Basically, create a dummy uitextfield that you never show. 
//I can't remember all the syntax :)


[dummyTextField becomeFirstResponder];
[dummyTextField resignFirstResponder];
//Keyboard should be gone. Hoorah!

Not sure 100% if this will work without flaws. If the keyboard starts to animate then hides itself again, you could use

[UIView enableAnimations:NO];

If the keyboard doesn't like being resigned while it's showing then you could try changing the inputView property of the dummy textField to some dummy UIView instead.

Hopefully this should get you somewhere!

Jordan Smith
  • 10,310
  • 7
  • 68
  • 114
  • I tried with the dummy textfield and a UIView but it doesn't work (iOS9). What works for me is calling webView.endEditing(true). See http://stackoverflow.com/questions/9108877/dimiss-keyboard-when-editing-textfield-on-uiwebview – endavid Jun 11 '16 at 10:07