UIPageViewController direction only forward

一个人想着一个人 提交于 2019-12-01 16:03:48

问题


The goal is to create a UIPageViewController that can only navigate forward. I am using a data source to provide the content for the UIPageViewController. The direction is set to UIPageViewControllerNavigationDirectionForward, the transition style is UIPageViewControllerTransitionStyleScroll.

The implementation of

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    // returns the next view controller
}

returns the next view controller, while the following should ensure navigating backwards is impossible

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    return nil;
}

Returning nil should indicate that navigation is not possible (as stated in the documentation). However, I am always possible to scroll back one page. Let's say I have 10 pages, I can scroll forward through all pages but at any page I can scroll back 1 page. (For example: at page 5 I can go back to page 4, at page 8 I can go back to page 7, and so on.)

I know I can avoid this by not using a data source and using the setViewControllers:direction:animated:completion: method, but I'd like to understand why my attempt is failing.


回答1:


This is the behavior you get when your pageViewController has its transition style set to scroll -- I'm not sure why, but it has something to do with a scroll view being inserted into the hierarchy somewhere (which I could see being allocated if I ran my project with Instruments turned on). If the transition is Page Curl, then you don't get any previous page being displayed if your return nil where you do.

So, I think you're stuck with using setViewControllers:direction:animated:completion: unless you want to switch to the Page Curl animation.




回答2:


Here is a simple solution, simply set isLeftScrollEnabled default value to false in the protocol: UIPageViewController with configurable scroll directions



来源:https://stackoverflow.com/questions/14426728/uipageviewcontroller-direction-only-forward

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!