IOS7 : UIScrollView offset in UINavigationController
I'm currently migrating my app on ios 7 and I've been stuck for hours on the new navigationcontroller/bar management.
Before, when we had a navigation controller, we had a snippet like this :
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:[[MainViewController alloc]init]];
In interface builder, we had the choice to set an existing navigationbar for the view and everything match the content of the real view.
OK so now, i have no clue of how to design properly with interface builder. I still have my snippet to initialize my navcontroller. However in the interface builder for my MainViewController if I set a status bar to translucent or opaque navigation bar, i have an offset of 44px at the top (see below).
Interface Builder_________________________And the result
Now, if i set status bar to none, there is no offset at top but since the view on simulator is smaller because of navigation bar the bottom of the view in interface builder is cut off.
Interface Builder_________________________And the result
I guess i'm really missing something here but i can't find any topic or apple info in iOS7 Transitions Guide about that.
Thanks for your help
EDIT
As we can see in the pictures, the first child of the view is a UIScrollView which contains both labels, the problem does not appear when there is no scrollview. It also appears if it's a UITableView. If a label is outside the UIScrollView, there is no offset to that label.
OK so i found the solution, I have set in my controller the property:
self.automaticallyAdjustsScrollViewInsets = false
I don't really understand the true benefit of this property though, (or why the default value is true)
The only documentation i found was there:
Update
In iOS 11 automaticallyAdjustsScrollViewInsets
is deprecated
You should now use:
self.tableView.contentInsetAdjustmentBehavior = .never
I also encourage you to check this question and its answer to get a better understanding of those properties
@Justafinger's answer worked like a charm for me as well.
Just wanted to add that this setting can also be adjusted easily from the interface builder.
I was running into this same issue, but I found a rather odd property on the ViewController in interface builder that seems to have been causing this for me. There is an "Extend Edges" set of check boxes. I removed the "Under Top Bars" check, and everything started laying out properly for me.
链接地址: http://www.djcxy.com/p/90316.html