18
votes

I'm currently transiting my application to iOS 7 (I want it to remain iOS 6 compatible). This question is not covered by the Apple NDA, it is a question about Auto Layout (it seems that iOS 7 forces Auto Layout (EDIT : was wrong, it is not forced)).

I have a navigation controller with a root view controller (obvious). With iOS 6, i was not using Auto Layout, so the root view controllers was below the navigation bar. With iOS 7, the frame origin does not include the navigation bar, so the top part of my content is hidden...

Have you an idea how to make the entire view above the navigation bar with Auto Layout ?

Thanks !

1
I may be wrong but I'd be surprised if Apple "forced" developers to use auto layout in iOS7? Is this definitely the case? (this information may be covered by the NDA!)bennythemink
Autolayout is not forced in iOS 7. It is improved.Adrian P
Its is forced. they didn't mentioned in the doc. Check the frame values before viewDidLoad and viewDidAppear . I don't use IB but still values differ .. What does this suggest ?? !!Kunal Balani
It is NOT forced. It's incredibly easy to turn it off. Same as iOS 6, in the Identity Inspector, uncheck "Use Autolayout".Matt Foley

1 Answers

22
votes

On iOS 7 you have the topLayoutGuide that specify the navigation bar. You can then specify that you want that the constraint of the tableview is on the topLayoutGuide and not the superview.

This will help you to know if it's iOS7 or not:

if ([self respondsToSelector:@selector(topLayoutGuide)])

So it can be something like that

NSString *verticalConstraint = @"V:|[v]|";
NSMutableDictionary *views = [NSMutableDictionary new];
views[@"v"] = self.tableview;
if ([self respondsToSelector:@selector(topLayoutGuide)]) {
    views[@"topLayoutGuide"] = self.topLayoutGuide;
    verticalConstraint = @"V:[topLayoutGuide][v]|";
}
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:verticalConstraint options:0 metrics:nil views:views]];
[self.view addConstraints:constraints];