2

I have a uiwebview inside the uipageviewcontroller, I want to be able to select some text in the view so I have userInteractionEnabled set to YES, but when I do that I loose the option of turning the page by tapping, although swiping still works fine.

What's the best way to trap the UITapReconizer on the UIWebview and pass it on to the UIPageviewController?

Thanks.

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
rudirudi
  • 73
  • 1
  • 5

2 Answers2

0

UIPageviewController has a gestureRecognizers property

My guess is that one if its gesture recognizer and yours - if your using one - can't act simultaneously. You could handle that through the gestures' methods, see question for handling multiple UITapGestureRecognizers, requiring your webView tap recognizer to fail for pageViewController's tap to succeed.

Like this (not tested)

UILongPressGestureRecognizer *yourTapGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];

for(UIGesture *gesture in yourPageController.gestureRecognizers){
   [gesture requireGestureRecognizerToFail:yourTapGesture];
}

[pageControllerTap requireGestureRecognizerToFail:yourTapGesture];

Also, I don't understand why you need userInteractionEnabled, is your UIWebView taking all space ? You could attach the gesture to webView's superview, and test webView-hit with locationInView: method.

Community
  • 1
  • 1
Vinzzz
  • 11,746
  • 5
  • 36
  • 42
  • Just to explain, I want to be able to select some of the text in the uiwebview to either share or record but using the default way of making a uimenu appear when doing a longpress. This doesn't happen when uiwebview.userInteraction = NO; – rudirudi Feb 07 '13 at 16:01
0

I've sorted it.

I've added a gesture recogniser to the controller generating the uiwebview:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self action:@selector(handleGesture:)];
    tapRecognizer.numberOfTapsRequired = 1;
    tapRecognizer.delegate = self;
    [webView addGestureRecognizer:tapRecognizer];

With

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

And adding in the pageviewController:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}
rudirudi
  • 73
  • 1
  • 5