Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable scrolling entirely in a WKWebView?

Tags:

ios

webview

I know this looks like a simple question one can simply say:

webview.scrollView.scrollEnabled = NO; webview.scrollView.panGestureRecognizer.enabled = NO; webview.scrollView.bounces = NO; 

or even

for (UIView* subview in webview.subviews) {   if ([subview respondsToSelector:@selector(setScrollEnabled:)]) {       [(id)subview setScrollEnabled:enabled];   }    if ([subview respondsToSelector:@selector(panGestureRecognizer)]) {       [[(id)subview panGestureRecognizer] setEnabled:enabled];   } } 

but while it does prevent scolling (in the contentOffset meaning) inside the WKWebviewit doesn't prevent it from receiving pan gesture events involving scrolling.

So articles like those of the Huffington Post, which have javascript included to automatically change articles when the user scrolls left or right still get that behavior.

How can I prevent this ?

like image 767
apouche Avatar asked Feb 20 '15 14:02

apouche


People also ask

How do I turn off bouncing effect in WKWebView?

What most people suggest is to use the following: wkWebView. scrollView. bounces = false .

How do I turn off scroll in singleChildScrollView flutter?

You can use the following code in your singleChildScrollView. physics: NeverScrollableScrollPhysics(), It stops it from being able to scroll.

How can I clear the contents of a UIWebView WKWebView?

To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .

What is WKWebView?

A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.


1 Answers

Before Swift 3

You can simply disable scroll on its implicit scrollView

webView.scrollView.scrollEnabled = false 

Swift 3

webView.scrollView.isScrollEnabled = false 
like image 146
Borut Tomazin Avatar answered Oct 07 '22 16:10

Borut Tomazin