当前位置:首页 > 开发 > 移动开发 > 正文

UIWebView左右划动翻页手势

发表于: 2012-05-25   作者:auauau   来源:转载   浏览:
摘要: 最近需要在UIWebView里实现左右划动翻页的功能,发现用UITouch事件没效果,在官方文档里找了个用UIGestureRecognizer实现的方法:    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@sel
最近需要在UIWebView里实现左右划动翻页的功能,发现用UITouch事件没效果,在官方文档里找了个用UIGestureRecognizer实现的方法:
  
 UISwipeGestureRecognizer  *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
    [webView addGestureRecognizer:swipeRight];
    [swipeRight release];
    
    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [webView addGestureRecognizer:swipeLeft];
    [swipeLeft release];

---------------------华丽的分割-------------------
-(void)swipe:(UISwipeGestureRecognizer *)g{
    if (g.direction == UISwipeGestureRecognizerDirectionRight) {
        [self prevPage];
    } else {
        [self nextPage];  
    }
}

UISwipeGestureRecognizer 是UIGestureRecognizer的子类,还有以下几个:
UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer

更详细的内容可以查看手册

本文出自 “idanal” 博客,请务必保留此出处http://danal.blog.51cto.com/3353275/632593

UIWebView左右划动翻页手势

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号