ios11 webview html canvas content got cleared by page scroll

孤街浪徒 提交于 2019-12-03 08:28:55

Same problem for me. I noticed that if I toggle in Safari Web Inspector any properties of the canvas, it is rendered again. Another similar issue is reported on SO (Cordova Webview canvas redering bug on recent iOS versions (10.3.1)).

So my plan is to detect the scroll event on top and force a redraw of the DOM element. I decided to use scrollstop event since scroll event is not well supported on mobile device. The touchmove event is working as well but it is not as good as scrollevent because it only occurs when the finger touches the screen.

$('#my-canvas').on({
    'scrollstop': function(e) {
        // e.scrollTop() doesn't work... so
        console.log($(window).scrollTop()); 
        if ($(window).scrollTop() === 0) {
           console.log("Redraw of the canvas");
           $('#my-canvas').hide().show(0);
        }
    }
});

Not convinced it is diamond code but it just works on iOS.

PS: The problem is maybe only existing for the legacy web view and not the WkWebView. But this last one is so challenging with a lot of different network'issues that i never was able to use it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!