2013-05-09 49 views
0

我有加UIWebViewUIViewController再加入彼此UIViewController在同一ViewController然后我想获得触摸上UIwebView获取触摸在web视图

回答

0

我有一个UIWebViewUIViewController的视图的孩子。为我工作(用于制表手势)的解决方案是这样的:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onDoubleTap:)]; 
tap.numberOfTapsRequired = 1; 
tap.delegate = self; 

[self.webView addGestureRecognizer:tap]; 

UIViewController正在实施从UIGestureRecognizerDelegate协议的下列方法(只retunning YES):

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

您必须添加手势

第一组代表in.h中文件

-(void)ViewDidLoad 
    { 
      UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] 
     initWithTarget:self action:@selector(HandleGesture:)]; 
     gesture.delegate=self; 
      gesture.numberOfTapsRequired = 1; 
     [YourWebview addGestureRecognizer:gesture]; 
    } 
    -(void)HandleGesture:(UITapGestureRecognizer *)sender 
    { 
     if (gesture.state == UIGestureRecognizerStateEnded) 
     { 

     } 
     if (gesture.state == UIGestureRecognizerStateBegan) 
     { 
        // You can write here any action 
     } 
    } 
    - (BOOL)gestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 
     // test if our control subview is on-screen 
     if ([touch.view isKindOfClass:[UIWebView class]]) { 
      // You can handle any thing 
      return YES; 
     }return NO; // handle the touch 
     } 
0

用于识别UIWebview的触摸事件,UIScrollview可以使用Gestures.don't忘了在.h文件中添加UIGestureRecognizerDelegate

UITapGestureRecognizer *single = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap)]; 
    single.numberOfTapsRequired = 1; 
    single.delegate = self; 
    [webview addGestureRecognizer:single]; 

-(void)oneTap{ 
    NSLog(@"single"); 
} 
0

请注意,来自手势识别器的触摸是视图而非​​基于页面的。因此,如果您希望自己的应用响应网页上的特定项目,无论它滚动或放大到哪里,最好使用URL方案向您的应用发送信号。