UIPageViewController方向只有前进 [英] UIPageViewController direction only forward

查看:108
本文介绍了UIPageViewController方向只有前进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标是创建一个只能向前导航的UIPageViewController。我正在使用数据源为UIPageViewController提供内容。方向设置为 UIPageViewControllerNavigationDirectionForward ,过渡样式为 UIPageViewControllerTransitionStyleScroll

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.

执行

- (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;
}

返回nil应表示无法导航(如文档中所述) 。但是,我总是可以向后滚动一页。假设我有10页,我可以向前滚动所有页面,但在任何页面我都可以向后滚动1页。 (例如:在第5页,我可以回到第4页,在第8页,我可以回到第7页,依此类推。)

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.)

我知道我可以通过不使用数据源并使用 setViewControllers:direction:animated:completion:方法避免这种情况,但我想了解为什么我的尝试失败。

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.

推荐答案

当你的pageViewController将其过渡样式设置为滚动时,这是你得到的行为 - 我不知道为什么,但它与滚动有关视图被插入到某个层次结构中(如果我在启用了Instruments的情况下运行我的项目,我可以看到它被分配)。如果过渡是Page Curl,那么如果你的回报为零,你就不会显示任何前一页。

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.

所以,我认为你被困在使用setViewControllers:direction:animated:completion:除非你想切换到Page Curl动画。

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

这篇关于UIPageViewController方向只有前进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆