UIWebView 实现翻页功能

转载  http://blog.csdn.net/iukey/article/details/7430984 

UIWebView 实现翻页功能

 UIWebView倒是经常用,不过翻页功能没用过,因为还没写过电子书之类的应用,最近心血来潮写了个电子书的框架,这样就可以量产电子书应用了,哈哈。可是要实现翻页功能时发现UIwebView竟然接收不了touch事件,老郁闷了。网上有大牛的hack方法,不过审核貌似通不过。组后发现苹果官方给我们提供了专门的api,通过 UISwipeGestureRecognizer 来实现。

直接上代码吧:

[java]  view plain copy print ?
  1. UISwipeGestureRecognizer  *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(previousPage)];  
  2.    swipeRight.direction=UISwipeGestureRecognizerDirectionRight;  
  3.    [webView addGestureRecognizer:swipeRight];  
  4.    [swipeRight release];  
  5.      
  6.    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(nextPage)];  
  7.    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;  
  8.    [webView addGestureRecognizer:swipeLeft];  
  9.    [swipeLeft release];  
一看代码应该就明白了。苹果官方给我们的手势有4个,分别对应上下左右:
[java]  view plain copy print ?
  1. typedef enum {  
  2.     UISwipeGestureRecognizerDirectionRight = 1 << 0,  
  3.     UISwipeGestureRecognizerDirectionLeft  = 1 << 1,  
  4.     UISwipeGestureRecognizerDirectionUp    = 1 << 2,  
  5.     UISwipeGestureRecognizerDirectionDown  = 1 << 3  
  6. } UISwipeGestureRecognizerDirection;  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值