我有一个带有2个VC(索引0和1)的UIPageViewController,我想避免用户在第一个视图(索引0)上向右滚动并在第二个视图(索引1)上向左滚动
有没有人可以告诉我该怎么做?
谢谢!
答案 0 :(得分:0)
尝试使用这些数据源方法:
@SWIFT版
public func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
var index = viewControllers.indexOf(viewController)
if index == 0 || index == NSNotFound {
return nil
}
index--
return viewControllerAtIndex(index)
}
public func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
var index = viewControllers.indexOf(viewController)
if index == NSNotFound {
return nil
}
index++
if index == viewControllers?.count {
return nil
}
return viewControllerAtIndex(index)
}
@OBJC版
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger index = [viewControllerArray indexOfObject:viewController];
if ((index == NSNotFound) || (index == 0)) {
return nil;
}
index--;
return [viewControllerArray objectAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSInteger index = [viewControllerArray indexOfObject:viewController];
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [viewControllerArray count]) {
return nil;
}
return [viewControllerArray objectAtIndex:index];
}
答案 1 :(得分:0)
您可以使用UIPageViewcontroller的Index值来实现此目的。但这很痛苦......让你检查一下。