An app I had working on iOS 7 and 8 has had some minor issues on iOS9, one of which being that a single view controller gets the wrong height.
The following code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self layoutViews];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self layoutViews];
}
- (void)layoutViews {
NSLog(@"Size-> %@", NSStringFromCGRect(self.view.frame));
}
Produces the following erroneous output:
2015-11-06 22:42:31.737 app[62442:1136052] Size-> {{0, 0}, {375, 667}}
2015-11-06 22:42:33.318 app[62442:1136052] Size-> {{0, 32}, {667, 343}}
2015-11-06 22:42:34.885 app[62442:1136052] Size-> {{0, 64}, {375, 603}}
2015-11-06 22:45:18.063 app[62442:1136052] Size-> {{0, 32}, {667, 343}}
When I:
- Open the VC in portrait
- Rotate to landscape
- Rotate back to portrait
- Rotate back to landscape
It seems that the initial load of the VC provides the wrong size under self.frame.size
, while all subsequent rotations are correct. The height of 603
is correct, but you can see that upon the two rotations to landscape that it's still incorrect at 667
.
I thought that something to do with the nav controller bar could be breaking it. My code in the viewDidLoad
method is simply:
- (void)viewDidLoad {
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
[super viewDidLoad];
}
Which works fine on iOS 8.
Update
Fixed this by adding the call to viewDidAppear
:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self layoutViews];
[activitiesTable flashScrollIndicators];
}