自Xcode 8起,Layout Interface Builder约束问题 [英] Layout Interface Builder constraints issue since Xcode 8

查看:141
本文介绍了自Xcode 8起,Layout Interface Builder约束问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我已将我的Swift项目更新为Swift 2.3和Xcode 8(发行版),所以我无法再完成我的界面了:

Since I have updated my Swift project to Swift 2.3 and Xcode 8 (release version) I can't get my Interface done anymore:

我正在完美地设置所有约束.一切正常.第二天我重新打开Xcode,我的所有视图"都是这样的.

I'm setting all the constraints perfectly. Everything works fine. I reopen Xcode the next day and all my Views look like this.

我也收到大量警告:

如果单击Update Frame,警告消失,视图再次恢复正常.但是,一旦我重新启动Xcode(或者有时甚至只是构建项目),它就会再次撤消...

If I click on Update Frame, the warning disappears and the View looks normal again. But as soon as I restart Xcode (or sometimes even just build the project) it's undone again...

重要:所有视图在所有设备中看起来都是完美的,并且是想要的,但是要保留概述确实很困难.

Important: All the Views look PERFECT and as wanted inside any devices, but it's really hard to keep the overview.

我花了一整夜时间来替换当前项目的所有元素.一切都很好,没有任何警告.第二天,警告又回来了,我实际上什么也没变.我该如何摆脱呢?非常感谢您的帮助.

I have spent a whole night replacing all the elements of my current project. Everything was fine without any warnings. The next day, the warnings were back and I had changed literally nothing. How do I get rid of this? Help is very much appreciated.

我可以更新框架",一切看起来都很好.经过几次构建或最晚重新打开Xcode之后,看起来又像这样.

I can "update the frame", everything looks good again. After a couple of builds or at the very latest after re-opening Xcode, it looks like this again.

最新示例:极其简单的屏幕. UIViewController. UINavigationBar. UITableView.没有争执.一个原型细胞.

Latest example: Extreme simple screen. UIViewController. UINavigationBar. UITableView. No segues. One Prototype Cell.

昨晚完美设置所有约束.重新打开Xcode.找到了.

Set all the Constraints perfectly last night. Reopened Xcode. Found this.

修改:

建议的解决方法是将所需控制器的模拟尺寸切换为检查器中的自由格式,然后更新框架,这只是一个临时解决方案.

The suggested work-around to switch desired controller's simulated size to freeform in inspector and then update frames is just a temporary solution.

当我重新打开Xcode时,所有警告再次返回.我可以将值更改为fixed,然后所有元素弹回"它们所需的位置,并且警告消失->重新打开Xcode,所有警告都回来了,控制器的元素又都滚了下来.

As soon as I re-open Xcode, all the warnings are back again. I can change the value to fixed then, all the elements "pop back" to their desired position and the warnings disappear -> reopen Xcode and all the warnings are back and the controller's elements are all in a tumble again.

将故事板文件类型更改为7.x的建议也没有任何效果.我按7.x,它问我是否要更改.我按确定.已加载.我打开了main.storyboard,它询问我要在哪个设备上打开情节提要.然后重新选择了Xcode 8.0.

Also the suggestion to change the storyboard file type to 7.x didn't have any effect. I pressed 7.x, it asked me, if I wanted to change. I pressed OK. Loaded. I opened the main.storyboard and it asked me in what device I wanted to open the storyboard on. Xcode 8.0 was re-selected then.

推荐答案

我正在研究一个大型项目,其中包含多个故事板和许多视图控制器.在大多数问题上都存在相同的问题.并认为这是发生的,因为Xcode现在支持带十进制值的约束.

I'm working on a large project with multiple storyboards and lots of viewcontrollers. Had same issues on most of them. And figured it is happening because Xcode now supports constraints with decimal values.

这是适用于我所有UITableViews和UICollectionViews的修复程序:

Here is the fix worked for all of my UITableViews and UICollectionViews:

1)从单元格内部的一个视图中仅删除"Height equals:xx"约束之一.
2)更新所有框架.
3)选择您从中删除约束的视图.
4)单击添加新的约束按钮.现在,它应该显示一个新的高度,可能带有一个十进制值.
5)在不更改框内值的情况下添加高度限制.

1) Remove only one of the "Height equals: xx" constraint from one of your views inside the cell.
2) Update all frames.
3) Select the view you removed constraint from.
4) Click to add new constraint button. Now it should be showing a new height, probably with a decimal value.
5) Add height constraint without changing the value inside the box.

您应该立即解决该单元的问题.对所有损坏的单元格重复此步骤.希望此解决方案也对您有用.祝你好运!

Your problem should be fixed for that cell now. Repeat this steps for all cells that are broken. Hope this solution works for you as well. Good luck!

这篇关于自Xcode 8起,Layout Interface Builder约束问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆