0

您好,我已经搜索了所有内容,但我没有弄清楚!

我有一个带有 5 个导航控件的选项卡栏控制器,在其中一个导航控件中,我有一个视图,里面有一个表格视图,当我单击该项目时,我推送一个新视图,该视图有

  view
     -webview
     -view

我创建了第二个视图(是透明的),因为我需要单击一下来隐藏我的工具栏和导航栏,并且 webview 正在吃掉所有的触摸!我把那个视图和实现在视图控制器上

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
 UITouch* touch = [touches anyObject];
 if(touch.tapCount == 2){
  [NSObject cancelPreviousPerformRequestsWithTarget:self];
 } 
 [[wv.subviews objectAtIndex:0] touchesBegan:touches withEvent:event];
 [super touchesBegan:touches withEvent:event];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
 [[wv.subviews objectAtIndex:0] touchesMoved:touches withEvent:event];
 [super touchesMoved:touches withEvent:event];
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
 UITouch* touch = [touches anyObject];
 if(touch.tapCount == 1){
  [self performSelector:@selector(hideBars) withObject:nil afterDelay:0.3];
 }
 [[wv.subviews objectAtIndex:0] touchesEnded:touches withEvent:event];
 [super touchesEnded:touches withEvent:event];
}

-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
 [[wv.subviews objectAtIndex:0] touchesCancelled:touches withEvent:event];
 [super touchesCancelled:touches withEvent:event];
}

wv 是我的 UIWebView IBOutlet 现在我可以在我的控制器中获取触摸并将它们发送到我的 webview。所以我认为一切正常,我可以滚动,但现在当我有链接时,我无法点击它们。并且 webview 正在检测我进行该测试的链接。所以任何其他方式来实现这一点以获得链接中的触摸,或者我应该改变这个解决方法来隐藏工具栏,这样我就可以拥有 webview 的全部功能?感谢您提前提供帮助。

4

1 回答 1

0

好的,我没有解决我的问题,但我得到了解决这种情况的方法。

UIWebView 获取所有触摸并且不将它们传递给其他视图,只有当您禁用用户交互时,我们不希望这样。而且你不能在 UIWebView 的实现中覆盖 touchesBegan 和那些东西。那么解决方案是什么?

正如我所提到的,如果您将 UIView 放在 UIWebView 之上,您可以获得触摸,并将它们传递给 webview,但这并不完美,因为您无法单击链接、缩放和所有这些东西,您只是可以滚动!这太糟糕了!

太好了,我的解决方法是:

驾驭位于 UIWebView 之上的 UIView,现在借助一些 javascript 来实现魔法!

在您的 html 中,您需要做一些技巧,首先:创建一个包含所有页面的 div,就在 body 之后,并将 padding 和 margin 设置为 0!并将其放在 div 上:

它的作用是,当您点击 div 时创建和事件,如果 div 填充了整个 webview,每当您单击时调用该事件,并且该事件更改地址,并且如果您将视图控制器设置为 webview 的委托,委托将调用此方法:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString* scheme = request.URL.scheme;
    NSString* query = request.URL.query;
    NSLog(@"%@, %@", scheme, query);
    if ([scheme compare:@"file"]==0){
        if ([query isEqualToString:@"hideBars"]){
            [self hideBars];
            return NO;
        }
    }

    return YES;
}

这就是魔术发生的地方,如果您单击任何地方,查询字符串将与 hideBars 字符串一起出现!所以它会调用我的 hideBars 函数!如果您单击链接,查询将附带链接地址,因此它也可以工作!zoom 不叫这个方法,所以它都很棒!

如果您有任何问题,请给我发邮件至 goncalo.falcao@waveweb2。com

于 2009-11-25T19:26:04.693 回答