1
我有一個viewcontroller嵌套在pageviewcontroller中,我想要細分爲兩部分(top + bottom)。我正確地分配了相應視圖的幀(下面的代碼),但是第一次渲染的幀不正確。當我滑開然後再回來時,渲染後的屏幕就是正確的。任何想法發生了什麼?在第一次繪製時,ios子視圖在pageViewController中的定位不正確
-(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);
}