Reputation: 597
I have a viewcontroller nested in a pageviewcontroller that I want to subdivide into two sections (top + bottom). I correctly assign the frames for the respective views (code below), but the first time it's rendered is incorrect. When I swipe away and then back again, the rendered screen is then correct. Any idea what's going on?
-(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);
}
Upvotes: 1
Views: 633
Reputation: 597
Figured out the problem. The issue isn't with the view controller that showed the split screen, but my custom pageviewcontroller.
I was adding the pageviewcontroller children in -viewDidLoad rather than -viewDidAppear. The difference is that -viewDidLoad did not have the correct dimensions of the superview and so all children view were calculated incorrectly.
Upvotes: 1