iOS:webview 滑动手势

标签 ios objective-c uiwebview uiswipegesturerecognizer

我有 2 个UIWebView 控件。使用这2个webview,我已经成功实现了滑动手势动画。

但问题是,当我单击下一个或上一个按钮时(哦,是的,我也有下一个、上一个、第一个和最后一个按钮来阅读一本书),滑动效果很好。

但是在 webview 上它工作得很奇怪。发生以下情况:

  • 滑动在 webview 上不起作用。
  • 当我点击下一个或上一个按钮然后滑动 webview 时,在 webview 上滑动有效。

以下是我的代码片段:

在viewDidLoad中:

  UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionLeft];
[webViewPage addGestureRecognizer:swipeRight];
[_webview2 addGestureRecognizer:swipeRight];


UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionRight];
[webViewPage addGestureRecognizer:swipeLeft];
[_webview2 addGestureRecognizer:swipeLeft];

在 UIWebView 上启用滑动

    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
//    NSLog(@"shouldRecognizeSimultaneouslyWithGestureRecognizer");
    return YES;
}



 - (IBAction)btnPrevious_click:(id)sender {
   //some code

}

- (IBAction)btnNext_click:(id)sender {
    //some code
}

我哪里错了?

最佳答案

从您的代码中,您必须在一个UIWebView名称中添加2个UISwipeGestureRecognizer,名称为_webview2,请更改根据您的要求。

关于iOS:webview 滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23465137/

相关文章:

ios - iOS 上的 native 代码部署

ios - 无法加载测试包,因为出现意外错误

ios - 如何使用 NSDateFormatter 将字符串日期转换为 NSDate

ios - Shopify iOS 移动购买 shipping_rate_id "can' t 为空”

objective-c - 如何在 iOS 中标记和取消标记行

ios - 使用 AVAssetExportSession 并保存在自定义相册中

objective-c - UIWebView 在切换到横向时不改变方向

iphone - 停止在 UIWebView 中播放视频

html - 在 Flash 影片中嵌入浏览器窗口

ios - HTML5 中嵌入的视频无法在 UIWebView 中播放