我有一个嵌套在 pageviewcontroller 中的 viewcontroller,我想将其细分为两个部分(顶部 + 底部)。我正确地为各个视图分配了框架(下面的代码),但是第一次渲染是不正确的。当我滑开然后再次返回时,渲染的屏幕是正确的。知道发生了什么吗?
-(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);
}