具有webview问题的导航视图系统与触摸!

时间:2009-11-25 14:59:23

标签: iphone webview

您好我已经搜索了所有内容,但我没想到这一点!

我有一个带有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的完整功能?请提前帮忙。

1 个答案:

答案 0 :(得分:0)

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

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

正如我所提到的,如果你把UIView放在UIWebView的顶部你可以得到触摸,并将它们传递给webview,但这也不完美,因为你无法点击链接,缩放和所有这些东西,你只能滚动!那太烂了!

Soooo,我的解决方法是:

获取位于UIWebView之上的UIView,现在借助javascript的帮助实现神奇!

在你的HTML中,你需要做一些技巧,首先: 创建一个包含所有页面的div,就在正文之后,并将填充和边距设置为0!把它放在div上:

这样做,点击div时创建和事件,div是否填满整个webview,每当你点击你调用那个事件,那个事件改变地址,如果你将视图控制器设置为委托在webview中,代表将调用此metod:

- (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不会调用这个metod所以太棒了!

如果您有任何疑问,请将我邮寄给goncalo.falcao @ waveweb2。 COM