当我按照我在StackOverflow上找到的答案时,我需要让UIWebView
认出touch
正在实施以下内容:
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
吗?
<{1}}根本不会被调用。
提前感谢您的帮助。
答案 0 :(得分:5)
self. webView.userInteractionEnabled = YES;
使用userInteractionEnabled方法并设置为YES。我认为这会对你有所帮助。
<强>编辑:强>
在WebVC.m类中使用-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
方法。
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
NSLog(@"shouldRecognizeSimultaneouslyWithGestureRecognizer");
return YES;
}
答案 1 :(得分:1)
for(UIGestureRecognizer *gesture in [webview gestureRecognizers])){
if([gesture isKindOfClass:[UITapGestureRecognizer class]){
if (gesture.numberOfTapsRequired == 1)
[webview removeGestureRecognizer:gesture];
}
}
然后添加你的手势。 就像你以前做过的那样