Javascript touchend(滚动)事件在ios 4中的UIWebView中不起作用

Javascript touchend (scroll) event dont work in UIWebView in ios 4

本文关键字:中的 UIWebView 不起作用 ios touchend 滚动 事件 Javascript      更新时间:2023-09-26

我在UIWebView中使用touchend事件如下:

window.ontouchend=function(touchEvent)
{
   ...
}

我用它来跟踪UIWebView中的滚动,这个事件通常在iOS 5+中工作,但这个事件在iOS 4中不工作!如何在iOS 4中跟踪javascript中的触摸端事件?

提前感谢您的帮助。

我没有找到在iOS4中使用此JS代码的方法所以我决定把这个代码留给iOS 5,但对于早期的iOS版本,我是从这个问题中做出决定的:如何拦截MKMapView或UIWebView对象上的触摸事件?

在我的viewController中,我写下了以下代码:

NSString *sysVersion=[[UIDevice currentDevice] systemVersion];
NSArray *sysVersionParse=[sysVersion componentsSeparatedByString:@"."];
int versionNum=[[sysVersionParse objectAtIndex:0] intValue]; //detect ios version
if (versionNum<5)
{
    WildcardGestureRecognizer * tapInterceptor = [[WildcardGestureRecognizer alloc] init];
    tapInterceptor.touchesEndCallback = ^(NSSet * touches, UIEvent * event)
    {
        NSString *jsString = [[NSString alloc] initWithFormat:@"window.ontouchend();"];
        [webview stringByEvaluatingJavaScriptFromString:jsString];
    };
    //and similarly for the other touch actions
    [webview addGestureRecognizer:tapInterceptor];
}

我希望有人得心应手!