Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable bouncing effect in WKWebView

I am running a WkWebView which is rendering my web content in my app. However when I am scrolling at the top/bottom of the page (vertically) the page bounces like a normal web page and I am losing the native User experience.

I have done some research on this topic which apperantly is a pretty common issue But non of the answeres resolved my problem.

What most people suggest is to use the following: wkWebView.scrollView.bounces = false. But for some reason it has no affect in my webView at all.

Help anyone?

i.e. I prefer solving the issue with native swift rather then injecting js etc..

like image 468
Hudi Ilfeld Avatar asked Mar 25 '18 10:03

Hudi Ilfeld


3 Answers

This is work for me:

wKWebView.scrollView.bounces = false
like image 196
missionMan Avatar answered Sep 28 '22 15:09

missionMan


for me, it works when I set these two:

webView.scrollView.alwaysBounceVertical = false
webView.scrollView.bounces = false

but some H5 still bouncing, I guess it's the situation caused by the website itself.

like image 39
sunshuyao Avatar answered Sep 28 '22 14:09

sunshuyao


This may be a problem with where you are doing this. This does not work when executed in the LoadView function. This only works if it is run in the ViewDidLoad function.

    override func viewDidLoad() {
        super.viewDidLoad()

        mainWebView.scrollView.bounces = false
        ...
like image 30
hong developer Avatar answered Sep 28 '22 15:09

hong developer