Dulgan
Dulgan

Reputation: 6694

How to replace SwipeGestureRecognizer action in a UIWebView

I'm trying to present local html5 content in a set of 5 UIWebViews. The idea is that the user would swipe to go to the 4 direction so I got 5 UIWebViews with bouncing disabled :

leftWebView.scrollView.bounces = NO;
middleWebView.scrollView.bounces = NO;
rightWebView.scrollView.bounces = NO;
upWebView.scrollView.bounces = NO;
downWebView.scrollView.bounces = NO;

We would assume that no scroll is possible in the webviews because the html pages displayed are smaller than the iPad Screen.

These web views are loaded so that the transition animated just by moving their center to be smooth.

So is there a way to change the swipe action performed by the gesture recognizers in the UIWebView?

I tried to put 4 SwipeGesturesRecognizers (one per direction) directly on the webViews but for some reason the gestures recognizer loose track of their WebViews when I swap references with :

UIWebView *tmp = leftWebView;
leftWebView = middleWebView;
middleWebView = rightWebView;
rightWebView = tmp;

I tried to use 4 SwipeGesturesRecognizers (one per direction) on a UIView on top of the window, but the taps are now blocked by this view, so that the user is not able anymore to interact with clickable elements.

Upvotes: 0

Views: 592

Answers (1)

Malek_Jundi
Malek_Jundi

Reputation: 6160

You could add a custom UISwipeGestureRecognizer to your webView .. and disable the scroll in the webView like this

UIScrollView *scroll = [[self.webView subviews] lastObject];

if([scroll isKindOfClass:[UIScrollView class]])
{
    scroll = (UIScrollView*)scroll;
    [scroll setScrollEnabled:NO];
}

Upvotes: 1

Related Questions