简体   繁体   English

在iphone 6 plus上自动布局的意外结果

[英]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. 我在视图控制器(VC)上添加了一个uiview,尝试设置它的宽度等于VC视图的宽度。

What I set and expected: 我设定和期望的内容: xcode设置和预期结果

And what i got on iphone 6 plus: 我在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? iphone 6+ autolayout有什么特别之处吗?

The view setting here is "Any width x Regular height" 此处的视图设置为“任意宽度x常规高度”

-------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). -------已添加2016年12月对于像我这样困惑的人:UIView中有一个布局边距属性,它是一个UIEdgeInsets(8,8,8,8)。 It is something like css padding. 这就像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. 当视图的边缘靠近超视图的边缘并且preservesSuperviewLayoutMargins属性为true时,可以增加实际的布局边距以防止内容与superview的边距重叠。

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. 侧边距取决于当前尺寸等级,但可以是16或20点。 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: 现在,删除约束并重新添加约束与Constrain到未选中的边距后,结果如下:

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

Sharon's answer works wonderfully, but you don't have to delete the existing constraints to solve the problem. Sharon的答案非常有效,但您不必删除现有的约束来解决问题。 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). 问题是我的View(完成按钮)位于基本视图层次结构中,因此我将视图带回根视图(视图控制器的视图)。 and set constraints accordingly. 并相应地设置约束。

My case set constraints Pin-> Uncheck Constraints to Margin -> Bottom,Leading,Trailing (Constraints value=0) 我的案例设置约束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. 我在iPhone 6 plus模拟器中遇到了这个错误。 But in the 6 plus device this bug didn't happen. 但是在6 plus设备中,这个bug并没有发生。 This could be just a bug with 6 plus simulators. 这可能只是一个6加模拟器的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自动布局和iPhone 6/6 Plus放错位置 - Autolayout and iPhone 6 / 6 Plus misplacements iPhone 6和6 Plus的AutoLayout TableView问题 - AutoLayout TableView issue with iPhone 6 and 6 Plus 自动布局仅在iPhone 7 plus中不起作用 - Autolayout not working only in iPhone 7 plus Autolayout限制不适用于iPhone 6和6 Plus - Autolayout constraints not working iPhone 6 and 6 Plus iOS 8 AutoLayout滚动视图在iPhone 6 plus上水平滚动 - iOS 8 AutoLayout scrollview scrolls horizontally on iPhone 6 plus 通过设备尺寸调整iOS自动布局字体(iPhone 6 plus,iPhone 6,iPhone 5) - iOS Autolayout font adjustment with device size (iPhone 6 plus, iPhone 6, iPhone 5) Autolayout center x alignment在iPhone 6 Plus上产生无限的布局循环 - Autolayout center x alignment resulting in infinite layout loop on iPhone 6 Plus 创建特定于iPhone Six Plus的UI元素(最好使用Autolayout) - Create iPhone Six Plus-Specific UI Elements (preferably with Autolayout) 使用iPhone6和6Plus进行缩放显示的Autolayout问题 - Autolayout issue with zoomed display with iPhone6 and 6Plus 旋转期间 UISplitViewController 和 UISearchController 的 iPhone 6 Plus Autolayout 问题 - iPhone 6 Plus Autolayout issue with UISplitViewController and UISearchController during rotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM