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!
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.
精彩评论