UINavigationController上的UIPageViewController在更改方向后不会重新布局其子视图控制器

时间:2013-11-03 17:07:24

标签: ios iphone objective-c ios7 uipageviewcontroller

我正在制作以下视图控制器(VC)结构。

[UINavigationViewController] - > [UIPageViewController] - > [UIViewControllers]

然后,这个VC应该支持纵向和横向。

我在改变任何方面的方向时遇到了一个问题。

enter image description here

你可以看到问题。 enter image description here

红色区域 是UIPageViewController上子VC的背景颜色。
蓝色区域 是UIPageViewController的背景颜色。

我猜孩子VC没有被UIPageViewController转发。我已经弄清楚了很久。我终于找到了一个解决方法,将以下重写函数添加到自定义 UIPageViewController。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [self setViewControllers:self.viewControllers
                   direction:UIPageViewControllerNavigationDirectionForward
                    animated:NO
                  completion:NULL];
}

虽然完成轮换后会显示向下移动视图。这段代码粗略地解决了这个问题。

无论如何,我真的想知道任何好的和自然的解决方案。

更新
我的应用程序在iOS6上运行良好。它可能是iOS7的bug?

1 个答案:

答案 0 :(得分:10)

我已经解决了这个问题,将以下SINGLE代码行放在自定义UIPageViewController的[viewDidLoaded]中。

self.automaticallyAdjustsScrollViewInsets = NO;

我认为UIPageViewController有一个滚动视图,如果它嵌入在UINavigationController中,它会因为改变方向而错误地布局。

幸运的是,我的解决方案符合问题。

@MirkoCatalano感谢您的评论。这些对于找到正确的解决方案非常有帮助。

相关问题