Ios5轻扫手势 [英] Ios5 swipe gesture

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

问题描述

我目前正在编写ios5应用程序并使用按钮调用两个函数(后退)和(下一个)。
我想用滑动手势调用它们。

I am currently writting an ios5 app and call two functions (back) and (next) with buttons. I would like to call them with swipe gestures instead.

这是可能的以及如何实现?

Would that be possible and how?

谢谢

推荐答案

向右方向(下一个按钮)和左方向(后退按钮)使用滑动手势
左方向:

Use swipe gesture for both right direction (next button) and left direction (back button) For left direction:

UISwipeGestureRecognizer *swipeLeft =[[UISwipeGestureRecognizer alloc]
    initWithTarget:self action:@selector(didSwipeLeft:)];
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
swipeLeft.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:swipeLeft];
[swipeLeft release];

正确方向:

UISwipeGestureRecognizer *swipeRight =[[UISwipeGestureRecognizer alloc]
    initWithTarget:self action:@selector(didSwipeRight:)];
swipeRight .direction=UISwipeGestureRecognizerDirectionRight;
swipeRight .numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:swipeRight ];
[swipeRight release];

您通过事件处理它们:

 -(void)didSwipeRight
 {
   //For right direction (next button)
 }

  -(void)didSwipeLeft
 {
   //For left direction (back button)
 }

这篇关于Ios5轻扫手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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