Questions about the navigation bar in iOS AutoLayout

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.