我试图在uiwebview中检测双击。以下是代码。当我调试时,调试器来到initwithcoder但从来没有触及到选择器功能。为什么呢?
我在我的xib文件中放置一个UIWebView,并将身份检查器类设置为MyWebView
#import "MyWebView.h"
@implementation MyWebView
- (void) initTap {
UITapGestureRecognizer *singleFingerDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerDoubleTap:)];
singleFingerDoubleTap.numberOfTouchesRequired = 1;
singleFingerDoubleTap.numberOfTapsRequired = 2;
[self addGestureRecognizer:singleFingerDoubleTap];
[singleFingerDoubleTap release];
}
- (id)initWithCoder:(NSCoder*)coder
{
if (self = [super initWithCoder:coder]) {
// Initialization code.
[self initTap];
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
[self initTap];
}
return self;
}
-(void)handleSingleFingerDoubleTap:(id)sender {
NSLog(@"Doulble click detected !");
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if (touch.tapCount == 2) {
//put you zooming action here
NSLog(@"Doulble click detected !");
}
}
- (void)dealloc {
[super dealloc];
}
@end
答案 0 :(得分:3)
您只需要将代理添加到识别器
singleFingerDoubleTap.delegate = self;
然后执行以下方法返回YES。
#pragma mark Gesture recognizer delegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
不要忘记将符合声明添加到您的类文件中。
喜欢这个
@interface ORWebViewController : UIViewController<UIGestureRecognizerDelegate>
答案 1 :(得分:-2)