Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7 to Xcode 8 Storyboard Constraint Warnings

Tags:

I just converted my Xcode project from Xcode 7.3 to Xcode 8 GM and I am getting over 80 constraint warnings. In Xcode 7, my storyboards were "big squares" rather than a specific iPhone size. Now, with Xcode 8, you can change to the different iPhone and iPad sizes. My constraints are still showing up as they were with the more squared-off VCs in Xcode 7. Is there a "quick" fix or do I need to go through my entire app and fix each and every constraint (far more than 80)?

UPDATE: September 20,2016 -> Many bug reports have been filed based on this feed and Apple should be aware of the problem. I will update with an answer as soon as the problem is fixed.

like image 509
Dan Levy Avatar asked Sep 08 '16 15:09

Dan Levy


People also ask

Why is the Xcode 7 storyboard square?

Apple for some reason has the size classes as though the iPad is square, which is why the Xcode 7 storyboard is square. A lot of landscape cases involving split-views or multitasking are taken care of for you.

What's new in Xcode 8?

Prior to Xcode 8, developers would have to know what all these sizes are and which device each belonged. That changed in Xcode 8 with a new user interface for Interface Builder. Xcode displays as selection of devices, the developer selects the devices, then Xcode previews the layout on that device.

How does Interface Builder work in Xcode?

That changed in Xcode 8 with a new user interface for Interface Builder. Xcode displays as selection of devices, the developer selects the devices, then Xcode previews the layout on that device.

How do I change the size of a constraint in Xcode?

Once you specified a size class to vary, just modify the constant for the constraint. Xcode keeps track of those changes. To make the Button 2 smaller for example, Click the iPad, vary for traits and select width. In the size inspector click Edit for the Top Space to Top Layout Guide constraint.Change from 10 to 100. Press Done Varying.


2 Answers

Select all the Scenes(View Controllers) in the Storyboard, show the Size inspector, change the Simulated Size to Freeform, then set Width Height = 600.

Then, those tons of warnings disappear.

enter image description here

like image 161
Xiang LI Avatar answered Sep 18 '22 18:09

Xiang LI


I had the same issue when updating to Xcode 8. My storyboard looked just like you describe. Check your warnings/errors. If they all say something like "set vertical hugging priority to X" or "set compression resistance to Y" then you should be able to fix your issue by setting the priorities as suggested.

Click a warning, then in the attribute inspector under the tab with the ruler icon (not sure what that tab is called) you can set the priorities under the Content Hugging Priority and Content Compression Resistance Priority headers. As you update these properties the warnings should start to change to incorrect frame warnings, at which point you can just update the frames.

This might not be a quick fix, but changing a few priorities for some constraints is easier than redoing all the constraints. I hope this helps!

like image 30
Rogoon Avatar answered Sep 20 '22 18:09

Rogoon