我想跳过两个UIViewcontrollers
通过滑动操作。
目前,我实施了UIScrollView
,并在其上添加了UIViewcontrollers
(vc1和vc2),所以
on vc1
向左滑动:跳转到vc2
向右滑动:什么都不做
on vc2
向左滑动:什么都不做
向右滑动:跳转到vc1
但我想要的是:
on vc1
向左滑动:跳转到vc2
向右滑动:跳转到vc2
on vc2
向左滑动:跳转到vc1
向右滑动:跳转到vc1
那么,如何实现?
答案 0 :(得分:0)
试试这个
步骤:
UIPageViewController
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
UIPageViewController
NSArray *viewControllers = //add your two view controllers in array;
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
UIPageViewController
添加为子视图控制器 self.pageController.dataSource = self;
[self addChildViewController:self.pageController];
现在,您需要实现两个方法
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [(ViewController *)viewController index];
if (index == 0) {
return nil;
}
// Decrease the index by 1 to return
index--;
return viewControllers[index];//[self viewControllerAtIndex:index];//viewControllerAtIndex
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(ViewController *)viewController index];
if (index == 1) {
return nil;
}
index++;
return viewControllers[index];
}