I have updated my iPhone to iOS 7 today and recompile my app for it and all views in .xib files and on device are moved up and their upper part is hidden by the navigation bar. In my viewController
I set self.edgesForExtendedLayout = UIRectEdgeNone;
and on iOS 7 now everything looks good but when I compile my project with Deployment Target 6.0 and tested it on iOS 6 device all views are hidden by the navigation bar again.How can I make them to look consistently on iOS 7 and iOS 6 simultaneously? I don't want to break iOS 6 support now.
Try using:
navigationController.navigationBar.translucent = NO;
Try this:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
So here is what I did. It's not the cleanest code ever and you need to make sure you don't get weird results with your scroll views.
Basically I move down all of the subviews by the height of the navbar (45). For my scrollviews/tableviews, which in my app always go to the bottom of the screen, I reduce their height by 45 so that you can still reach the end. This is a solution for some apps, but you should make sure that all of your scroll and tableviews are intended to be shrunk like this.
Because it's not recursive, you don't need to worry about tableviews in scrollviews or anything like that.
- (void)viewDidLoad
{
[super viewDidLoad];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
self.edgesForExtendedLayout = UIRectEdgeNone;
} else {
[self moveAllSubviewsDown];
}
}
- (void) moveAllSubviewsDown{
float barHeight = 45.0;
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y + barHeight, view.frame.size.width, view.frame.size.height - barHeight);
} else {
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y + barHeight, view.frame.size.width, view.frame.size.height);
}
}
}
If you're using Storyboards in Interface Builder with Autolayout, you can add a constraint for the top of your view with the "Top Layout Guide"
If you are using Interface Builder, I've had some luck with unchecking the setting for "extend edges" > "under top bars":
Works for me in iOS 7 and 6.
Add this value to your app plist: "View controller-based status bar appearance" and set it to "NO".
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