2011-09-19 77 views
2

我试图在uiwebview中检测双击。以下是代码。当我调试时,调试器来到initwithcoder,但从来没有touchesbegan也没有选择器功能。为什么这样 ?在UIWebView中检测双击

我把一个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 

回答

-2

在的情况下,要覆盖默认的双击缩放动作,this会引导你。

UPDATE:

请不要考虑上述引用的作者已经移动了它。

您可以找到Disabling default zoom effect.

+1

链接是死 – onmyway133

+1

@ onmyway133 - 感谢您的通知作为后太旧,那么可能引用链接可能已经删除。 –

+1

如果任何负面评价者分享了一个有效的URL来帮助其他股东,我们将不胜感激。 –

3

你只需要委托添加到识别

singleFingerDoubleTap.delegate = self; 

然后实现下面的方法来返回YES引用。

#pragma mark Gesture recognizer delegate 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
{ 
    return YES; 
} 

不要忘记为您的类文件添加符合声明。

像这样

@interface ORWebViewController : UIViewController<UIGestureRecognizerDelegate> 
+0

经过测试。有用!谢谢。 :) –