【发布时间】:2014-11-03 19:21:38
【问题描述】:
当触摸在 web 视图之外结束时,“onTouchEnd”不会触发。 使用 XCode 6、iOs 8、iPhone 6 编译
我有下一个布局:
|Navigation TAB|
|Left view|Web view|Right view|
|page view|
我可以在 Web 视图中接收所有触摸事件(触摸开始和结束时)。 但是,如果我在 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 colorWithRed:(45.0/255.0) green:(50.0/255.0) blue:(53.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
【问题讨论】:
标签: ios objective-c iphone webview uiwebview