Prevent UIWebView scrolling when keyboard appears

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

When the user touches the data entry field, the UIWebView scrolls up and remains so that the field remains visible to the user. Good.

I don’t mind scrolling (because everything under my form is hidden from the keyboard), but I would like the view not to scroll left.

Is there a way (headers on an html page or iOS code) to prevent this behavior?

thanks

+6
source share
3 answers

First you will need to display the keyboard display using UIKeyboardWillShowNotification .

Then limit the width of the contentSize UIScrollView (UIWebview) to the width of the screen, which ensures that the screen does not scroll horizontally.

0
source

I don't know how to completely prevent scrolling, but if you don't mind a little jitter, you can add this handler to the input field:

 onfocus="setTimeout('window.scroll(0,0)',100)" 
+1
source

not beautiful, but effective:

If you don't want your web browser to scroll at all, you can implement the UIWebView UIScrollViewDelegate and set the contentOffset to 0 on scrollViewDidScroll

 aWebView.scrollView.delegate = self func scrollViewDidScroll(scrollView: UIScrollView) { scrollView.contentOffset = CGPointMake(0, 0) } 
0
source

Source: https://habr.com/ru/post/914057/


All Articles