Reputation: 17080
I have a UIWebView hosted inside UIViewController, I manage to add the right\left gestures in the following way:
var swipeRight = UISwipeGestureRecognizer(target: self, action: "swiped:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.webView.addGestureRecognizer(swipeRight)
The problem that it's not working with up/down directions:
var swipeDown = UISwipeGestureRecognizer(target: self, action: "swiped:")
swipeDown.direction = UISwipeGestureRecognizerDirection.Down
self.webView.addGestureRecognizer(swipeDown)
I think it's because of the scrolling and I also tried to add it to the scrollview but it still doesn't recognize the up/down gestures:
self.webView.scrollView.addGestureRecognizer(swipeDown)
UPDATE:
I tried Harry answer but it override the default action of swipe up/down and I can't scroll the page:
self.view.addGestureRecognizer(swipeUp)
self.view.addGestureRecognizer(swipeDown)
self.webView.scrollView.panGestureRecognizer.requireGestureRecognizerToFail(swipeUp)
self.webView.scrollView.panGestureRecognizer.requireGestureRecognizerToFail(swipeDown)
Upvotes: 2
Views: 2903
Reputation:
In case of someone is still working on it, this solved my problem :
webView.scrollView.panGestureRecognizer.cancelsTouchesInView = NO;
upGesture.direction = UISwipeGestureRecognizerDirectionUp;
upGesture.cancelsTouchesInView = NO;
upGesture.delegate = self;
[webView.scrollView addGestureRecognizer:upGesture];
downGesture.direction = UISwipeGestureRecognizerDirectionDown;
downGesture.cancelsTouchesInView = NO;
downGesture.delegate = self;
[webView.scrollView addGestureRecognizer:downGesture];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return [gestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}
Upvotes: 1
Reputation: 3432
Add gesture recogniser to self.view
not UIWebView
instance.
self.view.addGestureRecognizer(swipeUp)
self.view.addGestureRecognizer(swipeDown)
Add these two lines after adding up/down gesture recognisers to web view.
self.webView.scrollView.panGestureRecognizer.requireGestureRecognizerToFail(swipeUp)
self.webView.scrollView.panGestureRecognizer.requireGestureRecognizerToFail(swipeDown)
Upvotes: 3