gpt4 book ai didi

iOS webview swipegesturerecognizer and zoom

转载 作者:行者123 更新时间:2023-12-01 18:56:24 27 4
gpt4 key购买 nike

在我的应用程序中,我有一个带有左右滑动手势识别器的 web View 。问题是当我放大 webview 时。似乎 swipegesturerecognizers 正在干扰 webview ScrollView 委托(delegate),并且 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
}

我用这个解决了它改变上面的委托(delegate)方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

最佳答案

您已经回答了自己的问题,但我将为将来发现此问题的人添加此答案:

如果只需要支持iOS 8+,可以使用WKWebView来自新 WebKit框架,替换 UIWebView . WKWebView支持开箱即用的向后/向前滑动(您需要将其 allowsBackForwardNavigationGestures 属性设置为 YES(默认为 NO ))。这意味着您无需为向后/向前滑动添加自己的手势识别器。

它的行为就像 Safari,这意味着它很好地处理了向前/向后滑动和缩放手势之间的区别。

关于iOS webview swipegesturerecognizer and zoom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26421348/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com