3

我是iPhone开发人员的新手,

我制作了 epub 阅读器并在我的webview

我想要的是,当用户right swipe gesture第二次做然后我想导航到新页面时,我不想在用户right swipe gesture第一次做任何事情时做任何事情。

UISwipeGestureRecognizer *swipeRight

有没有类似的方法,

if(swipeRight.touch.count > 2)
{
  // do this
}

任何帮助都会得到帮助。

提前致谢 !

编辑

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    float scrollViewHeight = scrollView.frame.size.height;
    float scrollContentSizeHeight = scrollView.contentSize.height;
    float scrollOffset = scrollView.contentOffset.y;

    if (scrollOffset == 0)
    {
        swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self  action:@selector(swipeLeftAction:)];
        swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
        swipeUp.numberOfTouchesRequired=2;
        swipeUp.delegate = (id<UIGestureRecognizerDelegate>)self;
        swipeUp.cancelsTouchesInView=YES;
        [_webview addGestureRecognizer:swipeUp];  
    }
    else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
    {
        swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self  action:@selector(swipeRightAction:)];
        swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
        swipeDown.numberOfTouchesRequired=2;
        swipeDown.delegate = (id<UIGestureRecognizerDelegate>)self;
        swipeDown.cancelsTouchesInView=YES;
        [_webview addGestureRecognizer:swipeDown];

    }
4

4 回答 4

6

你可以告诉 UIWebView 的 UIScrollView 它的 UIPanGestureRecognizer 应该只在你自己的 UISwipeGestureRecognizer 失败时触发。

这就是你的做法:

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];

那应该对你有用。

于 2013-09-16T18:02:52.083 回答
4

只需将 UIGestureRecognizer 子类附加到该视图并等待调用...

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
于 2012-06-25T10:48:25.157 回答
1
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];
于 2012-06-25T10:18:57.560 回答
1

我不认为滑动手势为您所针对的行为类型提供支持,但您可以通过执行以下操作轻松完成它:

  1. 在第一次滑动时,设置一个标志并启动一个计时器;其余的什么都不做;

  2. 在第二次滑动时,

    一种。如果计时器已触发(触发时,计时器重置标志),请按照第 1 点执行。

    湾。是计时器没有触发(标志仍然设置),那么你采取行动并取消计时器。

您可能会想到定义 UISwipeGestureRecognizer 的子类来封装所有这些行为。

于 2012-06-25T10:44:52.650 回答