我有一个以编程方式实现的 UIPageViewController 的 iPad 项目。当我将设备切换到横向模式时,我在它的委托方法中将 pageViewController 的脊椎位置更改为 Mid:
-(UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation{
if (UIInterfaceOrientationIsPortrait(orientation)){
ChildViewController *viewController = (ChildViewController *)[self pageControllerAtIndex:currentPageIndex];
[pageViewController setViewControllers:@[viewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
return UIPageViewControllerSpineLocationMin;
} else {
ChildViewController *first = (ChildViewController *)[self pageControllerAtIndex:currentPageIndex];
ChildViewController *second = (ChildViewController *)[self pageControllerAtIndex:currentPageIndex+1];
[pageViewController setViewControllers:@[first,second] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
return UIPageViewControllerSpineLocationMid;
}
}
然后我的 UIPageViewController 显示两个页面,在我开始分页之前它看起来很好。问题是:它的一个子视图控制器(在我开始翻转的一侧)占用了设备屏幕的所有空间,因此另一个页面隐藏在它下面。在 childViewController 的课程中,我发现在 -(void)viewWillAppear 方法中,框架的宽度都很好(我需要它是 512 - 我屏幕的一半),但在 -(void)viewDidAppear 方法中它已经是 1024。