简体   繁体   中英

Unexpected result for autolayout on iphone 6 plus

I've added a uiview on a view controller(VC), trying to set it's width is equals to VC's view's width.

What I set and expected: xcode设置和预期结果

And what i got on iphone 6 plus: 我在ip6 +上得到了什么

I've tried to change the constants of leading space and trailing space and no help. Is there any special for iphone 6+ autolayout?

The view setting here is "Any width x Regular height"

-------Added Dec 2016 To people who is confused by this case like me: There is a layout margin property in UIView, which is an UIEdgeInsets(8,8,8,8). It is something like css padding.

When the edge of your view is close to the edge of the superview and the preservesSuperviewLayoutMargins property is true, the actual layout margins may be increased to prevent content from overlapping the superview's margins.

The default margins are eight points on each side.

If the view is a view controller's root view, the system sets and manages the margins. The top and bottom margins are set to zero points. The side margins vary depending on the current size class, but can be either 16 or 20 points. You cannot change these margins.

Try to remove the check Constrain to margins when adding constraints. Here take a look:

Constrain to margins is checked and its result

限制利润结果

Now, after removing the constraints and re-adding the constraints with Constrain to margins unchecked, here is the result:

未经检查限制边距结果没有约束到边距

Sharon's answer works wonderfully, but you don't have to delete the existing constraints to solve the problem. You may edit existing constraints removing the extraneous margin:

在应用解决方案前解决方案步骤申请解决方案后

Editing existing constraints to remove the extraneous margin will not work. You have to delete the existing constraints and add new ones keeping constraints to margin unselected.

I faced same issue for my "Done" button. The issue was my View (Done Button) was in base View hierarchy so i bring view back in root view (view controller's view). and set constraints accordingly.

My case set constraints Pin-> Uncheck Constraints to Margin -> Bottom,Leading,Trailing (Constraints value=0)

在此输入图像描述

Make sure view hierarchy should not be following way.(Subview might be but cut view must not).

在此输入图像描述

I had this bug in the iPhone 6 plus simulator. But in the 6 plus device this bug didn't happen. This could be just a bug with 6 plus simulators.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM