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 WKWebview
it 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 ?
What most people suggest is to use the following: wkWebView. scrollView. bounces = false .
You can use the following code in your singleChildScrollView. physics: NeverScrollableScrollPhysics(), It stops it from being able to scroll.
To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .
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.
Before Swift 3
You can simply disable scroll on its implicit scrollView
webView.scrollView.scrollEnabled = false
Swift 3
webView.scrollView.isScrollEnabled = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With