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

时间:2013-04-04 07:10:43

标签: ios objective-c

我正在处理笑话的应用程序,我还有一个功能仍然缺失,它显示了笑话文本视图,以同样的方式在Iphone中逐个显示照片,并让用户从右向左滑动手指,或者反之亦然:

有没有人有例子或知道一个?

2 个答案:

答案 0 :(得分:0)

如果我理解你的要求,你正在寻找UIPageViewController

设置UIPageViewController非常简单。

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

然后只需设置委托,并创建相应的委托方法,你就完成了!

委托方法可以从UIPageViewController的{​​{3}}引用。

祝你好运!欢迎来到Stack Overflow!

答案 1 :(得分:0)

执行此操作以检测滑动:

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


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

//将其添加到您想要的视图

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

//处理程序代码:

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