detect Swipe gesture in UIWebview

前端 未结 4 1668
走了就别回头了
走了就别回头了 2021-01-14 15:54

I am new to iPhone developer,

I made epub reader and loaded each page of epub in my webview

What i want to is, when user does

4条回答
  •  庸人自扰
    2021-01-14 16:48

    You can tell the UIWebView's UIScrollView that its UIPanGestureRecognizer should only fire when your own UISwipeGestureRecognizer has failed.

    This is how you do it:

    UISwipeGestureRecognizer *rightSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    UISwipeGestureRecognizer *leftSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    rightSwipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
    leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:rightSwipeGesture];
    [self.view addGestureRecognizer:leftSwipeGesture];
    
    [_webView.scrollView.panGestureRecognizer requireGestureRecognizerToFail:rightSwipeGesture];
    [_webView.scrollView.panGestureRecognizer requireGestureRecognizerToFail:leftSwipeGesture];
    

    That should do the trick for you.

提交回复
热议问题