UIPageViewController

时间:2015-05-18 15:25:07

标签: ios objective-c cocoa-touch uipageviewcontroller nslayoutconstraint

在故事板中,我UINavigationController没有导航栏,根视图控制器UIPageViewController有2个孩子:LoginVCChoosePlaceVC

MainPageVC 是UIPageViewController的一个简单子类,我刚刚设置了

[self setViewControllers:@[loginVC] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

在Login ViewController中,我将约束设置为顶部,将徽标图像设置为0(徽标到屏幕顶部的距离为0)。但是当我第一次看到状态栏中的distance为20时,只有当我在UIPageViewController中转到下一个VC时(weakSelf是对自定义UIPageViewController的弱引用):

[weakSelf setViewControllers:@[choosePlaceVC] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {

        }];

然后返回登录VC:

[weakSelf setViewControllers:@[loginVC] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {

        }];

从徽标到状态栏becomes 0的距离。当我重复移动到下一个VC并返回时,距离保持= 0(并且该距离正确)

为什么第一次出现距离= 20?

1 个答案:

答案 0 :(得分:1)

经过长时间的调查,我发现了它:

在Extend Edges中的UIPageViewController的属性检查器中的Storyboard中,我在“顶栏和底栏”下的复选框中取消选中。

现在固定中约束的奇怪行为(我注意到在这种情况下我无论如何都偏离了视图的顶部= 20 px,但始终保持不变。但是如果添加主视图的子视图的大小与主视图一样,如果我将所有元素添加到此子视图中,则距离顶部的距离= 0 px)。