IOS - 没有 "touchend"事件不全屏 webview
<p><p>当触摸在 webView 之外结束时,“onTouchEnd”不会触发。
使用 XCode 6、iOs 8、iPhone 6 编译</p>
<p>我有下一个布局:</p>
<pre><code>|Navigation TAB|
|Left view|Web view|Right view|
|page view|
</code></pre>
<p>我可以在 WebView 中接收所有触摸事件(触摸开始和结束时)。
但是,如果我在 webview 中开始触摸,然后将触摸移出它,我会在离开 webview 边框后立即停止接收 touchmove 事件,并且不会收到 touchend 事件。</p>
<p>测试html文件的代码:</p>
<pre><code><head>
</head>
<body bgcolor="#CC6"
ontouchmove="console.info('move');"
ontouchstart="console.info('start');"
ontouchend="console.info('end');"
ontouchcancelled="console.info('canceled');"
>
<h1>This is a test</h1>
<p> Lore ip sum </p>
</body>
</code></pre>
<p>“viewDidLoad”函数代码</p>
<pre><code>;
// Do any additional setup after loading the view, typically from a nib.
self.webView = [ initWithFrame:self.mainView.bounds];
;
;
/* Disable scrolling of web view */
for (id subview in ) {
if (]) {
((UIScrollView*)subview).bounces = NO;
}
}
self.webView.scrollView.bounces = NO;
self.webView.scrollView.canCancelContentTouches = NO;
self.webView.scrollView.scrollEnabled = NO;
self.webView.backgroundColor = ; //;
self.webView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin| UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
;
NSString * localHtmlFilePath = [ pathForResource:@"main" ofType:@"html" inDirectory:@"www"];
NSString *html = ;
;
</code></pre>
<p>如何解决这个问题?是否有一些我遗漏的配置?</p>
<p>完整的源代码可以在这里找到:<a href="https://github.com/Daraku/WebViewBug" rel="noreferrer noopener nofollow">https://github.com/Daraku/WebViewBug</a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在过去的 30 分钟里我一直在苦苦挣扎,最后我决定实现一个超时,它会随着每个 <code>touchmove</code> 恢复并从 <code>touchstart</code> 开始,并在 <code>touchend</code> 上被清除。超时是为了让我们说 <code>1500ms</code>,如果我没有从 webview 中按应有的方式触发 <code>touchend</code>,我会在超时结束时触发它。</p>
<p>希望我说明了一点。它并不完美,但可以作为部分修复。在我的情况下,iScroll(_execEvent('scrollCancel'))</p></p>
<p style="font-size: 20px;">关于IOS - 没有"touchend"事件不全屏 webview,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26721447/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26721447/
</a>
</p>
页:
[1]