Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检测HTML5上的触摸<;视频>;在iPhone上的UIWebView中_Iphone_Objective C_Html_Uiwebview_Webkit - Fatal编程技术网

检测HTML5上的触摸<;视频>;在iPhone上的UIWebView中

检测HTML5上的触摸<;视频>;在iPhone上的UIWebView中,iphone,objective-c,html,uiwebview,webkit,Iphone,Objective C,Html,Uiwebview,Webkit,我希望能够在UIWebView中检测标签上的触摸/点击事件。但它看起来并没有对那个事件做出反应。有什么想法吗 videoElement.addEventListener('touchstart', myFunc, false); 也可能是“点击”事件。有一种方法可以做到这一点,但它并不漂亮 UIWebView允许您运行任意javascript,例如[webview stringByEvaluatingJavaScriptFromString:@“document.getElementsByTa

我希望能够在UIWebView中检测标签上的触摸/点击事件。但它看起来并没有对那个事件做出反应。有什么想法吗

videoElement.addEventListener('touchstart', myFunc, false);

也可能是“点击”事件。

有一种方法可以做到这一点,但它并不漂亮

UIWebView允许您运行任意javascript,例如
[webview stringByEvaluatingJavaScriptFromString:@“document.getElementsByTagName('html')[0].innerHTML”]
。因此,当用户点击videoElement时,可以运行javascript来设置特定元素的innerHTML,您可以从这个函数中获取该元素

但是,您如何知道何时在Objective-C端运行此函数?嗯,有两种选择。首先(尽管我不建议这样做,因为这样做会很慢),您可以设置一个轮询函数,该函数每隔一段时间运行一次,通过EvaluatingJavaScriptFromString:函数检查
stringByEvaluatingJavascriptFromString:
函数的值。第二种选择,我认为可能是最好的选择,是对WebView进行子类化,以便在WebView上观看触摸。因此,您可以重写以下函数:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    NSString *string = [self stringByEvaluatingJavascriptFromString:@"document.getElementById('videoTapped').innerHTML"]
    if ([string isEqual:@"Something"]) {
        // do something here
    }
} 

设置视频元素以在点击时加载特定URL(使用
onclick
或仅使用普通锚定),然后在webView的
委托中执行
-webView:shouldStartLoadWithRequest:navigationType:
回调以查看该URL