2

当我按照我在 StackOverflow 上找到的答案时,我所需要UIWebViewtouch只是实现以下内容:

WebVC.h

#import <UIKit/UIKit.h>

@interface WebVC : UIViewController <UIWebViewDelegate, UIGestureRecognizerDelegate>

@property (nonatomic, copy) NSString *test;

@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;

@property (strong, nonatomic) UITapGestureRecognizer *tapGestureR;

- (void)handleTap:(id)sender;

@end

WebVC.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.webView.delegate = self;

    self.tapGestureR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    self.tapGestureR.delegate = self;
    [self.webView addGestureRecognizer:self.tapGestureR];
}

- (void)handleTap:(id)sender
{
     NSLog(@"tapDetected");
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return YES;
}

你知道我为什么看不到NSLog吗? Method根本不会被调用。

提前感谢您的帮助。

4

2 回答 2

5
self. webView.userInteractionEnabled = YES;

使用 userInteractionEnabled 方法并设置为 YES。我想这会对你有所帮助。

编辑:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 在您的 WebVC.m 类中使用方法。

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
     NSLog(@"shouldRecognizeSimultaneouslyWithGestureRecognizer");
    return YES;
}
于 2013-02-25T13:20:13.263 回答
1
    for(UIGestureRecognizer *gesture in [webview gestureRecognizers])){
       if([gesture isKindOfClass:[UITapGestureRecognizer class]){
         if (gesture.numberOfTapsRequired == 1) 
            [webview removeGestureRecognizer:gesture];
       }
    }

然后添加你的手势。就像你以前做过的那样

于 2013-02-25T13:43:25.563 回答