View controller frame size in the controller

I implement the localization of the UIViewcontroller. In the example below, I set the frame size of the child controllers in the root controller. The child view is displayed as the size that I set, however, when I check its borders in container 1, it reports a different size size that I set.

Root controller (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); } 

The console exit from the container 1 view dims 768.000000 1004.000000

I thought the problem was setting the view frame on the UIScreen] applicationFrame main screen. So I deleted all this code so that uiview is generated automatically. The problem still persists.

+6
source share
1 answer

View frames are not actually used in viewDidLoad; you must move all your geometry control code to viewWillAppear. The system will clobber any changes that you set to viewDidLoad between them, and when it is about to come to the screen.

+5
source

Source: https://habr.com/ru/post/919978/


All Articles