【问题标题】:Javascript touchend (scroll) event dont work in UIWebView in ios 4Javascript touchend(滚动)事件在ios 4的UIWebView中不起作用
【发布时间】:2012-08-23 14:33:41
【问题描述】:

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

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

我用它来跟踪 UIWebView 内的滚动,这个事件在 iOS 5+ 中正常工作,但这个事件在 iOS 4 中不起作用! 如何在 iOS 4 的 javascript 中跟踪 touchend 事件?

提前感谢您的帮助。

【问题讨论】:

    标签: javascript ios4 scroll touch-event


    【解决方案1】:

    我没有找到在 iOS 4 中使用此 JS 代码的方法 所以我决定将这段代码留给 iOS 5,但对于早期的 iO​​S 版本,我从这个问题中做出了决定: How to intercept touches events on a MKMapView or UIWebView objects?

    在我的 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];
    }
    

    希望有人能帮上忙!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-22
      • 2015-03-24
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      相关资源
      最近更新 更多