Ios5 swipe gesture

巧了我就是萌 提交于 2019-12-21 03:04:30

问题


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?

Thanks


回答1:


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

For right direction:

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

You handle them with events:

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

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


来源:https://stackoverflow.com/questions/10990060/ios5-swipe-gesture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!