Swipe gestures in WKWebView

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Swipe gestures in WKWebView



So I have a WKWebView inside a UICollectionViewCell. I have to open few webpages but those webpages are eating up the scrolling by overriding touchmove event as below:


WKWebView


UICollectionViewCell


touchmove


document.addEventListener('touchmove', function(e) {
e.preventDefault();
}



I have tried adding swipe gestures to WKWebView and its superview. touchesMoved: is also not getting called inside superview. I cant disable userInteraction on webview as I want to be able to tap and interact with webview.


WKWebView


superview


touchesMoved:


userInteraction



I tried overriding the existing touchmove event of webpage by injecting script:


touchmove


WKUserScript *script = [[WKUserScript alloc]initWithSource:@"window.ontouchmove = function() {
window.webkit.messageHandlers.touchmoved.postMessage('Touches Moved..');
return true;
};" injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];

WKUserScript *docscript = [[WKUserScript alloc]initWithSource:@"document.ontouchmove = function() {
window.webkit.messageHandlers.touchmoved.postMessage('Doc Touches Moved..');
return true;
};" injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
[config.userContentController addUserScript:script];
[config.userContentController addUserScript:docscript];
[config.userContentController addScriptMessageHandler:self name:@"touchmoved"];



I was getting callback in didReceiveScriptMessage but it dint enable scrolling.


didReceiveScriptMessage



Is there any way to enable scrolling or to add swipe gestures for such webpages?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived