I am implementing UIViewcontroller containment. In the example below I set the frame size of the childcontrollers in the rootcontroller. The child view appears as the size I have set, however when I check on its bounds within container1 it reports a different size to the size I set.
Rootcontroller (container)
- (void)viewDidLoad
{
[super viewDidLoad];
self.containA = [[Container1 alloc]init];
self.containB = [[Container2 alloc]init];
self.containA.view.frame = CGRectMake(50, 50,50, 50);
self.containB.view.frame = CGRectMake(50, 50, 300, 300);
[self addChildViewController:self.containA];
[self addChildViewController:self.containB];
[self.view addSubview:self.containA.view];
Container1
-(void)viewDidLoad {
[super viewDidLoad];
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//[self.view addSubview:view];
self.view = view;
self.view.backgroundColor = [UIColor redColor];
[view release];
NSLog(@"view dims %f %f",self.view.bounds.size.width,self.view.bounds.size.height);
}
Console output from container 1 view dims 768.000000 1004.000000
I thought the issue was related to setting the view frame to UIScreen main screen]applicationFrame .So I removed all of this code so the uiview is created automatically. The issue still remains..
-viewDidLoad
. If you are programmatically creating your view instead of using a storyboard or a nib, you must create it and set it-loadView
. Also, a view controller should really never change its view's frame. The parent controller or the window always gets to do that. – West