Ctak
Ctak

Reputation: 253

Gestures within a UIWebView, iPad

Right now this is the code I have to handle gestures within a webView:

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]     initWithTarget:self action:@selector(swipeRightAction:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
[webView1 addGestureRecognizer:swipeRight];
//</code>

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]     initWithTarget:self action:@selector(swipeLeftAction:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = self;
[webView1 addGestureRecognizer:swipeLeft];


[super viewDidLoad];
}

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

- (void)swipeRightAction:(id)ignored
{
NSLog(@"Swipe Right");
//add Function
}

- (void)swipeLeftAction:(id)ignored
{
NSLog(@"Swipe Left");

scrollView.contentOffset = CGPointMake(webView2.frame.origin.x,  webView1.frame.origin.y);
}

The purpose of this code is to scroll through three webViews that are side by side in a scrollView.

It works for the first webView, but eventually I'll want to put the gesture onto all the webViews, and if I try to put it on the second one, it doesn't work for the first. Any ideas as to why and a possible solution to this problem? Thanks in advance!

Upvotes: 1

Views: 1793

Answers (1)

Mikey
Mikey

Reputation: 1332

Perhaps the gesture recognizer would work best in the view hosting the UIWebViews. Voila, you'd only need one recognizer, which should make it's management much easier.

Upvotes: 1

Related Questions