OGeek|极客世界-中国程序员成长平台

标题: IOS - 没有 "touchend"事件不全屏 webview [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:31
标题: IOS - 没有 "touchend"事件不全屏 webview

当触摸在 web View 之外结束时,“onTouchEnd”不会触发。 使用 XCode 6、iOs 8、iPhone 6 编译

我有下一个布局:

|Navigation TAB|
|Left view|Web view|Right view|
|page view|

我可以在 Web View 中接收所有触摸事件(触摸开始和结束时)。 但是,如果我在 webview 中开始触摸,然后将触摸移出它,我会在离开 webview 边框后立即停止接收 touchmove 事件,并且不会收到 touchend 事件。

测试html文件的代码:

  <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>

“viewDidLoad”函数代码

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

self.webView = [[UIWebView alloc] initWithFrame:self.mainView.bounds];

[self.webView setScalesPageToFit:YES];
[self.webView setAlpha:1];

/* Disable scrolling of web view */
for (id subview in [self.webView subviews]) {
    if ([subview isKindOfClass:[UIScrollView class]]) {
        ((UIScrollView*)subview).bounces = NO;
    }
}

self.webView.scrollView.bounces = NO;
self.webView.scrollView.canCancelContentTouches = NO;
self.webView.scrollView.scrollEnabled = NO;

self.webView.backgroundColor = [UIColor magentaColor]; //[UIColor colorWithRed45.0/255.0) green50.0/255.0) blue53.0/255.0) alpha:1];
self.webView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin| UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.mainView addSubview:self.webView];


NSString * localHtmlFilePath = [[NSBundle mainBundle] pathForResource"main" ofType"html" inDirectory"www"];
NSString *html = [NSString stringWithContentsOfFile:localHtmlFilePath encoding:NSUTF8StringEncoding error:nil]; 



[self.webView loadHTMLString:html baseURL:nil];

如何解决这个问题?是否有一些我遗漏的配置?

完整的源代码可以在这里找到:https://github.com/Daraku/WebViewBug



Best Answer-推荐答案


在过去的 30 分钟里我一直在苦苦挣扎,最后我决定实现一个超时,它会随着每个 touchmove 恢复并从 touchstart 开始,并在 touchend 上被清除。超时是为了让我们说 1500ms,如果我没有从 webview 中按应有的方式触发 touchend,我会在超时结束时触发它。

希望我说明了一点。它并不完美,但可以作为部分修复。在我的情况下,iScroll(_execEvent('scrollCancel'))

关于IOS - 没有 "touchend"事件不全屏 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26721447/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4