如何在UIWebView上检测触摸

Sat*_*yam 13 iphone touch uiwebview

在UIWebview上,如何检测触摸?

但是,当用户单击某个URL或触摸控件时,则不会.

有可能处理它吗?

Bhu*_*dra 34

使用UIGestureRecognizerDelegate方法:

在声明文件中添加UIGestureRecognizerDelegate(即您的.h文件)

第1步:只需设置gestureRecognizer的委托:(在.m文件viewDidLoad中)

UITapGestureRecognizer *webViewTapped = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
webViewTapped.numberOfTapsRequired = 1;
webViewTapped.delegate = self;
[offScreenWebView addGestureRecognizer:webViewTapped];
[webViewTapped release];
Run Code Online (Sandbox Code Playgroud)

第2步:覆盖此功能:(在.m文件中)

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

第3步:现在实现tapAction功能:

- (void)tapAction:(UITapGestureRecognizer *)sender
{    
    NSLog(@"touched");

    // Get the specific point that was touched
    CGPoint point = [sender locationInView:self.view];
}
Run Code Online (Sandbox Code Playgroud)