Using iOS8. Frame size of UIViewController's
view is incorrect in viewDidLoad
and viewDidAppear
.
I could get the correct frame size from viewDidLayoutSubviews
and perform view updates (I need to invalidate a layout) but than handling rotation with viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
becomes pointless and the 2 methods duke it out.
Ideally willTransitionToSize
would be called and not didLayoutSubviews
, but not both, because I don't know if I truly need to invalidate the layout and perform pointless calculation, layout, etc.
I want to avoid using all sorts of magic flags pertaining to rotation and frame size changes.
Is there any way to get the "true" size of the view controller view before any of this happens?
EDIT
Here is some example code:
-(void)viewDidLoad {
[super viewDidLoad];
NSLog(@"My Frame = %@",NSStringFromCGRect(self.view.frame)); // prints 320x568 i.e. the whole screen
// more setup code...
self.someView = [SomeClass alloc] initWithFrame:self.view.bounds];
self.someView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// add some more views and masks
}
-(void)viewDidAppear {
[super viewDidAppear];
NSLog(@"My Frame = %@",NSStringFromCGRect(self.view.frame)); // prints 320x568 i.e. the whole screen
// view "sticks" out the bottom of the screen still - don't know if I need to layout "self.someView". I could add "viewWillLayoutSubviews" but than rotation wouldn't be animated - because I wouldn't know which condition to take...
}
// if the view controller rotates than need to update appearance in a nice animated way
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self updateAppearance];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
}];
}