ios - 在 WkWebView 中拦截滑动边缘

标签 ios objective-c cocoa-touch uigesturerecognizer wkwebview

当客户端向左/向右滑动时,在 webview 中它应该调用我的代码(即从 handleRightEdgeGesture 打印日志)。它不会发生。这是为什么?

这是我目前的代码。

#import "ViewController.h"
@import App;
@interface ViewController ()
@end


@interface ViewController () <UIGestureRecognizerDelegate> {
    CGFloat _centerX;
}


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    // track swipe left/right gestures

    UIScreenEdgePanGestureRecognizer *leftEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftEdgeGesture:)];
    leftEdgeGesture.edges = UIRectEdgeLeft;
    leftEdgeGesture.delegate = self;
    [self.view addGestureRecognizer:leftEdgeGesture];

    UIScreenEdgePanGestureRecognizer *rightEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightEdgeGesture:)];
    rightEdgeGesture.edges = UIRectEdgeRight;
    rightEdgeGesture.delegate = self;
    [self.view addGestureRecognizer:rightEdgeGesture];

    // launch the webview

     self.productURL = @"http://localhost:3010";

     NSURL *url = [NSURL URLWithString:self.productURL];
     NSURLRequest *request = [NSURLRequest requestWithURL:url];

     _webView = [[WKWebView alloc] initWithFrame:self.view.frame];
     //_webView.allowsBackForwardNavigationGestures = TRUE;
     [_webView loadRequest:request];
     _webView.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
   // add the gesture trackers to the webview 
    [_webView addGestureRecognizer:rightEdgeGesture];
    [_webView addGestureRecognizer:leftEdgeGesture];
    [self.view addSubview:_webView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)handleLeftEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture {
    // Get the current view we are touching
    if(UIGestureRecognizerStateBegan == gesture.state ||
       UIGestureRecognizerStateChanged == gesture.state) {
        // CGPoint translation = [gesture translationInView:gesture.view];
        NSLog(@"DEBUG: gesture left complete %@", nil);
    } else {  // cancel, fail, or ended
        // reset
        NSLog(@"DEBUG: gesture left reset %@", nil);
    }
}

- (void)handleRightEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture {

    // Get the current view we are touching

    if(UIGestureRecognizerStateBegan == gesture.state ||
       UIGestureRecognizerStateChanged == gesture.state) {
      //  CGPoint translation = [gesture translationInView:gesture.view];
        // gensture complete?

        NSLog(@"DEBUG: gesture right complete %@", nil);
    } else {  // cancel, fail, or ended
        // reset
        NSLog(@"DEBUG: gesture right reset %@", nil);

    }

}



@end

最佳答案

虽然我宁愿完全取消 webkitview 手势控制,但我不知道如何添加“多手势”支持似乎可以让它工作。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    return YES;
}

关于ios - 在 WkWebView 中拦截滑动边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42893421/

相关文章:

ios - 如何等到 UITableView 内置动画完成?

objective-c - 如何在 NSMutableArray 中存储 CGContext 状态?

ios - IOS MapView中有没有注解标题回调函数或者设置目标的方法?

iphone - 苹果股票应用程序中的图表

ios - 在 iOS 设备上显示基于 Flash 的 youtube 视频

ios - swift 我可以知道同样的事情是怎么发生的吗?

ios - 在非弧形环境中的 block 内使用 self 和 self 属性

ios - Facebook 按钮委托(delegate)无法正常工作

ios - iOS 中的滚动条可见性

iOS 配置 - 如果我创建临时配置,它会破坏应用商店中现有应用的 APN 吗?