In storyboard, you can add a navigation bar controller to a controller if you use the Editor>embed>navigation controller
When you drag a view and add a constraint to the view, you will have the option top layout guide, so that the view will be displayed close to the navigation bar in the case of horizontal screen and vertical screen.
However, when the new file is created, the xib created together does not have this option, in order to make the view close to the navigation bar display, the top must be constrained to 64, but in the horizontal screen state will be in the navigation bar and the center of the view of white bar, because the horizontal screen state will disappear, The hight of the navigation bar will become smaller.
I have tried to use Sizeclass to solve this problem, in 4,5,6, 6P, 6s no problem, but on 6sP, the navigation bar in the horizontal screen when the hight did not change, instantly want to vomit blood
Then I thought of a more complicated solution:
Use the Automaticallyadjustsscrollviewinsets property to adapt to the navigation bar, as follows
First drag a scrollview on the Xib, then set the upper and lower left and right constraints all to 0
Then drag a view to ScrollView, four constraints are all 0, this time there will be a constraint report red, regardless, continue to add constraints to the view
Add a horizontal constraint first
Add a height constraint again
At this time, we find that the constraint error disappears, so that after the constraint, the width of the ScrollView contentsize is the breadth of the screen, high is our height constraint on the view
When we add self.automaticallyadjustsscrollviewinsets = YES in the Viewwillappear method;
The position of the navigation bar is automatically vacated, and our controls are constrained on the view to achieve the same effect as the navigation bar.
The final point
Although this method can solve the problem, but very troublesome, add a lot of layers, do not know if there is no direct setting xib can be solved by simple method
Which God knows to help?
Under the willing to use an apple to change!!!
Questions about the navigation bar in iOS AutoLayout