1

クライアントが左/右にスワイプすると、コードを呼び出す必要があります(つまり、ログをhandleRightEdgeGestureから印刷する)。それは起こりません。何故ですか?WkWebViewのスワイプインターセプト

これまでのコードは次のとおりです。

#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 

答えて

1

「マルチジェスチャー」のサポートを追加する私はむしろ完全にwebkitviewジェスチャーコントロールを解除だろうが、私は方法がわからないのにそれを動作させるように思われます。

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

    return YES; 
} 
0

あなたはWKWebViewに、それぞれの特性allows​Magnificationallows​Back​Forward​Navigation​Gesturesを使用して倍率ジェスチャーとナビゲーションジェスチャーを無効にすることができるはずです。

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

    return YES; 
} 

との組み合わせで、あなたが求めているものを行う必要があること。