在我的应用程序中,我有一个带左右swipegesturerecognizers的webview。问题是当我放大webview时。似乎swipegesturerecognizers扰乱webview scrollview委托和webview缩放工作不好。我怎么能正确地做到这一点?
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
[webView addGestureRecognizer:swipeRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = self;
[webView addGestureRecognizer:swipeLeft];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return YES;
}
- (void)swipeRightAction:(id)ignored
{
NSLog(@"Swipe Right");
//add Function
}
- (void)swipeLeftAction:(id)ignored
{
NSLog(@"Swipe Left");
//add Function
}
我解决了它改变上面的委托方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
答案 0 :(得分:3)
您已经回答了自己的问题,但我会为将来发现此问题的人添加此答案:
如果您只需要支持iOS 8+,则可以使用新WKWebView
框架中的WebKit
替换UIWebView
。 WKWebView
支持开箱即用的后退/前进(您需要将其allowsBackForwardNavigationGestures
属性设置为YES
(默认为NO
))。这意味着您不需要为后退/前进滑动添加自己的手势识别器。
它的行为就像Safari一样,这意味着它可以很好地处理前进/后退滑动和缩放手势之间的区别。
答案 1 :(得分:0)
我解决了它改变上面的委托方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}