detect Swipe gesture in UIWebview

前端 未结 4 1630
走了就别回头了
走了就别回头了 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:31

    Just attach UIGestureRecognizer subclass to that view and hold on for calls...

    UISwipeGestureRecognizer* rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(someAction)];
    rightSwipeRecognizer.numberOfTouchesRequired = 2;
    rightSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    rightSwipeRecognizer.cancelsTouchesInView = YES;
    [self.webView addGestureRecognizer:rightSwipeRecognizer]; // add in your webviewrightSwipeRecognizer
    
    0 讨论(0)
  • 2021-01-14 16:40

    I don't think that swipe gestures offer support for the kind of behavior you are aiming at, but you can easily accomplish it by doing the following:

    1. on the first swipe, set a flag and start a timer; for the rest do nothing;

    2. on the second swipe,

      a. if the timer has fired (when firing, the timer reset the flag), do as per point 1.

      b. is the timer has not fired (the flag is still set), then do you action and cancel the timer.

    You might event think of defining a subclass of UISwipeGestureRecognizer to encapsulate all this behavior.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-14 16:57
    Try like below it will help you
    UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
        rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
        rightRecognizer.numberOfTouchesRequired = 2;
        [self.view addGestureRecognizer:rightRecognizer];
        [rightRecognizer release];
    
    0 讨论(0)
提交回复
热议问题