我正在处理笑话的应用程序,我还有一个功能仍然缺失,它显示了笑话文本视图,以同样的方式在Iphone中逐个显示照片,并让用户从右向左滑动手指,或者反之亦然:
有没有人有例子或知道一个?
答案 0 :(得分:0)
如果我理解你的要求,你正在寻找UIPageViewController
。
设置UIPageViewController
非常简单。
UIPageViewController *pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
然后只需设置委托,并创建相应的委托方法,你就完成了!
委托方法可以从UIPageViewController
的{{3}}引用。
答案 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.
}
}