I have a view controller that was written back in the days of iOS 5 and I'm trying to transition it to iOS 7. After reading the iOS 7 transition guide and poking around on SO, I discovered that I need to set the new iOS 7 property edgesForExtendedLayout to UIRectEdgeNone to prevent one of my custom subviews from appearing 49 pixels higher on iOS 7 than it appears on iOS 6. However, after setting that property, my custom subview is still appearing 49 pixels higher on iOS 7 and I don't know what else I need to do. Here's my simple code that I added to my viewDidLoad method...
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
and here's the code for creating and adding the custom subview that is appearing higher on iOS 7...
CGRect customControlFrameRect = {{0.0f, 240.0f}, {100.0f, 100.0f}};
self.customControl = [[MyCustomControl alloc] initWithFrame:customControlFrameRect];
self.customControl.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:self.customControl];
One other important detail, if it helps, is this view is created from a nib file, but the custom subview that is appearing higher on iOS 7 than iOS 6 is the only subview that is created and added programmatically in viewDidLoad, after I set the edgesForExtendedLayout property. All the other subviews that are created from the nib aren't affected regardless of the whether or not I set the egdesForExtendedLayout property.
My two questions are...
Thanks in advance for your wisdom!
It is the purpose of edgesForExtendedLayout which was set to UIRectEdgeNone to not extend the view in any direction, but your view will now start in origin within the screen size (now below the statusBar!) when using a frame with position of 0, 0 (like you did with the customControl). You need to adjust the frame of your view/viewController to represent that you want to start under the statusBar/navigationBar or make the status/nagivationBar opaque; or add UIRectEdgeTop if only used for one view.
Setting the navigationController to opaque will also do so with the statusBar:
self.navigationController.navigationBar.translucent = NO;
Because the interface builder sets the frame correctly under the navigationBar by default, you could change it of course. And it uses UIRectEdgeAll and autoresizing.
I've found, in some cases, that setting the edgesForExtendedLayout in viewWillAppear: rather than viewDidLoad gives me the result I'm looking for. This may not solve your problem, but it has helped me in a few cases and hopefully it'll help others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With