简体   繁体   English

从右向左滑动手指,反之亦然:-)

[英]slide the finger from right to left, or vice versa :-)

I am working on application for jokes and I have one feature still missing which is showing jokes text view on the same way of showing photos in Iphone, one by one, and having the user slide the finger from right to left, or vice versa : 我正在开发笑话应用程序,但我仍然缺少一个功能,该功能与在Iphone中一张一张显示照片的方式相同,显示笑话文本视图,并让用户从右向左滑动手指,反之亦然:

Does anyone has an example or knows of one? 有没有人有一个例子或知道一个例子?

You're looking for a UIPageViewController if I'm understanding what you're asking. 如果我了解您的要求,那么您正在寻找UIPageViewController

Setting up a UIPageViewController is pretty easy. 设置UIPageViewController非常简单。

UIPageViewController *pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

Then simply set the delegate, and create the respective delegate methods, and you're all set! 然后,只需设置委托,并创建各自的委托方法,便一切就绪!

delegate methods can be referenced from UIPageViewController 's class reference . 可以从UIPageViewController类引用中引用委托方法。

Good luck! 祝好运! And welcome to Stack Overflow! 欢迎使用Stack Overflow!

Do this for detecting swipes: 这样做是为了检测滑动:

UISwipeGestureRecognizer *swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;


UISwipeGestureRecognizer *swipeRightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionRight;

// Add it to the view you want //将其添加到所需的视图

 [self.view addGestureRecognizer:swipeLeftRecognizer];
 [self.view addGestureRecognizer:swipeRightRecognizer];

//the handler code: //处理程序代码:

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
     //do something when swiped left.
}
else  if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) 
  {
   //do something when swiped right.
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM