简体   繁体   中英

Layout Interface Builder constraints issue since 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:

在此处输入图片说明

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

Also I'm getting tons of warnings:

在此处输入图片说明

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.

在此处输入图片说明

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.

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

在此处输入图片说明

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

Edit :

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

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.

在此处输入图片说明

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.

在此处输入图片说明

Quick workaround: change the desired controllers' simulated size to freeform in inspector and then update frames. Looks like freeform controllers are not affected by these new Xcode 8 IB features :)

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.

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

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!

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