iosuiwebview

Prevent UIWebView to scroll when keyboard appears


I have a UIWebView presenting a page containing input fields ().

When the user touches the field to enter data, the UIWebView is scrolled up and left to make the field stay visible for the user. Well ok.

I don't mind it is scrolled up (because everything below my form is hidden by the keyboard) but I would like to prevent the view from being scrolled left.

Is there a way ( headers in the html page, or iOS code) to prevent this behavior ?

Thanks


Solution

  • First you will have to capture the display of a Keyboard using UIKeyboardWillShowNotification .

    Then restrict the contentSize width of the UIScrollView (of the UIWebview) to screen width which will ensure that the screen doesnot scroll horizontally.