在 UIWebview 中检测滑动手势 [英] detect Swipe gesture in UIWebview

查看:23
本文介绍了在 UIWebview 中检测滑动手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iPhone 开发者的新手,

I am new to iPhone developer,

我制作了epub阅读器并在我的webview中加载了epub的每一页

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

我想要的是,当用户第二次执行 右滑动手势 然后我想导航到新页面,当用户执行 右滑动手势时我不想做任何事情 第一次.

What i want to is, when user does right swipe gesture 2nd time then i want to navigate to new page, i do not want to do anything when user does right swipe gesture for first time.

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

    }

推荐答案

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

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

这篇关于在 UIWebview 中检测滑动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆