我有一个嵌套在 pageviewcontroller 中的 viewcontroller,我想将其分割为两个部分(顶部 + 底部)。我正确地为各个 View 分配了帧(下面的代码),但是第一次渲染时不正确。当我滑开然后再滑回来时,渲染的屏幕是正确的。知道发生了什么事吗?
-(void) viewDidLoad
{
self.controller1 = [self.storyboard
instantiateViewControllerWithIdentifier: @"controller1"];
self.controller2 = [self.storyboard
instantiateViewControllerWithIdentifier:@"controller2"];
[self.view addSubview:self.controller1.view];
[self.view addSubview:self.controller2.view];
[self addChildViewController:self.controller1];
[self addChildViewController:self.controller2];
}
- (void)viewWillAppear
{
UIInterfaceOrientation orientation = self.interfaceOrientation;
BOOL navigationBarHidden = [self.navigationController isNavigationBarHidden];
CGRect navigationBarFrame = self.navigationController.navigationBar.frame;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGRect viewSize = self.view.frame;
self.controller1.view.frame =
CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.width);
self.controller2.view.frame =
CGRectMake(0, screenBounds.size.width,
screenBounds.size.width, applicationFrame.size.height - screenBounds.size.width);
}
最佳答案
解决了问题。问题不在于显示分屏的 View Controller ,而是我的自定义 pageviewcontroller。
我在 -viewDidLoad 而不是 -viewDidAppear 中添加了 pageviewcontroller 子项。不同之处在于 -viewDidLoad 没有正确的父 View 尺寸,因此所有 subview 的计算都不正确。
关于第一次绘制时 pageViewController 中的 ios subview 定位不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13464762/