我正在制作以下视图控制器(VC)结构.
[UINavigationViewController] – > [UIPageViewController] – > [UIViewControllers]
那么,这个VC应该支持纵向和横向.
我所遇到的一个问题是改变方向到任何一方.
你可以看到问题.
红色区域是UIPageViewController上子VC的背景颜色.
蓝色区域是UIPageViewController的背景颜色.
我猜孩子VC没有被UIPageViewController转发.我已经弄清楚了很久.我终于找到了一个解决方法,将以下重写函数添加到自定义UIPageViewController.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [self setViewControllers:self.viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL]; }
虽然完成轮换后会显示向下移动视图.这段代码粗略地解决了这个问题.
无论如何,我真的想知道任何好的和自然的解决方案.
UPDATE
我的应用程序在iOS6上运行良好.它可能是iOS7的bug?
解决方法
我已经解决了这个问题,将以下SINGLE代码行放在自定义UIPageViewController的[viewDidLoaded]中.
self.automaticallyAdjustsScrollViewInsets = NO;
我认为UIPageViewController有一个滚动视图,如果它嵌入在UINavigationController中,它会因为改变方向而错误地布局.
幸运的是,我的解决方案符合问题.
@MirkoCatalano感谢您的评论.这些对于找到正确的解决方案非常有帮助.