现在这是我必须在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);
}
此代码的目的是滚动浏览scrollView中并排的三个webView。
它适用于第一个webView,但最终我想将手势放到所有webView上,如果我尝试将它放在第二个上,它就不适用于第一个。关于为什么以及可能解决这个问题的任何想法?提前谢谢!
答案 0 :(得分:1)
也许手势识别器在托管UIWebViews的视图中效果最佳。瞧,你只需要一个识别器,这样可以使管理变得更容易。