Xcode 7 to Xcode 8 Storyboard Constraint Warnings - ios

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.

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.

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!

Select the view controllers one by one and press "Update Frames" each time.

Related

Warning frame for "Navigation bar" will be different at run time appears in Xcode 8 Swift 3

Before I've upgraded to Xcode 8 I haven't seen this error in such case. I have different Navigation Controllers. For all of them I see an error Frame for "Navigation bar" will be different at the run time. Navigation bar "Expected: width=384, Actual: width=375. In reality these Navigation Controllers doesn't have Navigation bar. Navigation bar exists for subviews. Anyway I could solve it by tick and untick the checkbox Shows navigation bar in Attributes inspector. But unfortunately every time I reopen Main.storyboard this warning appears again. Also if I click on yellow triangle and then on update frames nothing happen.
Warning will disappear if you change the property "Simulated Size" to "Freeform".
As mentioned here you can fix this by toggling Adjust Scrollview Insets on/off.
I have changed from View as: iPhone 6S to iPhone 5S, then changed back to iPhone 6S, and Xcode did all the changes to remove the warning.
This worked for me at Xcode 8.3.1
After restarting Xcode, it would still work.
Select Navigation Controller
Go to Show the Size Inspector
Change Simulated Size to Freeform
Change Simulated Size back to Fixed
Then the warnings disappear.
As a workaround just to get rid of the annoying warning I have been editing Main.storyboard manually by removing 'misplaced' in:
<navigationBar key="navigationBar" opaque="NO" contentMode="scaleToFill" misplaced="YES" translucent="NO" id="Os1-Xh-7XN">
A hack but it is nice to have zero warnings rather than 1 :)
Click "View As" at the bottom left of your storyboard and choose a different device size, then click it again and swap back to the device size you started with. This worked for me.
Until Xcode 8 is patched, you can set the "View as:" option to "iPhone SE" to eliminate the warning. Not ideal, but works for now.
I tried all the above suggestions but it didn't seem to work. I think it might be a more serious bug.
I have logged a bug with Apple Bug Reporter( link: https://bugreport.apple.com/logon) - if you want to do the same, then please reference bug : 31355220 so that Apple can tie it together. The more people that report it - the more information they will have to fix this annoyance.
I was able to get rid of the issue completely by setting the simulated size of the view controller to freeform and then setting the width from 375 to 320.
Had the same issue, here's what I did to fix:
Expand the error information and click on the warning detail. Xcode should then automatically open the dimension/position settings. Replace the current value with the value suggested in the warning details.
Basically, make sure that the size in your runtime is the same as the size you have specified in the size inspector.
You can also click the icon beside the image you posted (the yellow triangle with white circle. Sometimes, its a red circle icon) then there will be options to automatically fix/adjust the issues.
I chose the update constraints option then adjusted the new constraints accordingly.
for me the problem was that i was hiding the bottom bar on push (using IB checkbox).
i had to select 'none' in 'bottom bar' option:
Okay so it looks like I've fixed the issue. Here's what I did.
Select update frames like normal. Open a different file and then click back on the storyboard file. If that doesn't work then restart Xcode. It looks like it was updating internally but the interface builder UI was stuck as it sometimes gets.
Please change your device Preview in xcode for View controller and compile and check for warnings...
Xcode 8 is bit buggy, Interface builder reset its with random no which affects all contained views.
Try changing your preview device.
Xcode 12
I think this problem is mostly because the width of device preview is different per various devices. E.g. iPhone 12 and iPhone 11 have different screenWidth. If you set a fix value on width of some view and give it some constraints, then it may not adopt your current previewed iPhone's screen width, so it complained "different size in run time".
And for me, I set an UIView and ImageView's width & height as fixed value in size inspector with iPhone 11 preview. And gives it also fixed 10 points leading and trailing constraints in IB. Then it complained if I switch to iPhone 12 preview.
To fix it, I select the viewController and chose "Update Frames". Then it looks better but Xcode still complain one conflict constraint after the change. Eventually, I manually found and fix it in IB.

Xcode missing constrains although app not using size classes?

I have an older app which is not using size classes and I will not use constrains in this app. I did some changes on the layout (using xcode 7.2) and since than I am getting some errors "missing constraints" although I am NOT using size classes? And it is true from time to time the layout is wrong (but not ever?). How can I turn off constrains for this screen?
If you want to let xcode set constraints then you can select reset to suggested constraints as follows..

Inhibit `Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0` warnings

I have an abundant amount of Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0 warnings in my project in ~80 xib files. I have attempted to fix these warnings using answers found here: Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0, but this led to AutoLayout issues.
Fixing all the consequential effects is not something our team wants to take on, and furthermore QA. I know how to turn off all warnings for xib files in a target. How do I ignore this specific warning?
Find all the multi-line UILabels in your project (Lines = 0 in Attributes Inspector) and set their Preferred Width property in Size Inspector to 0 (check the Explicit check box).
Check the label constrain, the answer was to click on the constraint, and then look in the Utilities bar (on the right). As shown in the picture below, click on an item and then make sure that "relative to margin" is unchecked.

Automatic constraints to storyboard and xib in XCode 6?

I was just trying to learn Autolayout in XCode 6. But I noticed a strange change in the XCode 6 that is whenever I drag and drop a button (or any UI element) on a xib the XCode isn't automatically adding the constraints to the button. However I do remember this facility was there in the previous versions of XCode. But in XCode 6 I had to explicitly add the constraints to the UI element. Here are the images of what happens in previous version of Xcode 6 and previous version of Xcode .
There we can see in XCode 6 no constraints have been added by default but however in previous version of XCode constraint was added by default.
So it would be helpful if you guys let me know if there's a way to enable the feature of adding constraints by default in XCode 6 or is it the way XCode 6 ways where we need to add constraints manually?
Thanks in advance :)
With the introduction of size classes, to have a universal storyboard for both iPhone and iPad, setting the constraints automatically wouldn't make much sense for me.
You can ask Xcode to resolve auto layout issues for you by pressing the (Resolve Auto Layout Issues) button in the lower right of the Interface Builder window and choosing “Add Missing Constraints”. The added constraints will fix the subviews relative to their superviews.
Adding the constraints automatically while editing was done in Xcode 4, and it was a disaster. Every time you moved a view, it broke something.
As of 5, any missing constraints will be added at compile time to your views. If you select a view and look in the size inspector, it will tell you this. See here for more details on constraints and interface builder.

Layout attributes relative to the layout margin on iOS versions prior to 8.0

What would be causing the following warning (and subsequent alignment issues on iOS 7)?
Attribute Unavailable: Layout attributes relative to the layout margin on iOS versions prior to 8.0
None of the posted answers solved the problem for me. But the reason for this is the following: Xcode 6 creates constraints based on relative margins by default. Those are only available on iOS 8.0 and newer. You get these warnings when your deployment target is set to iOS 7.0 or lower.
The way I fixed the warning:
Click the warning in Xcode
Attribute inspector will open the constraint
Search for item that has margin (see screenshot)
Turn off Relative to margin option
Disable "Prefer margin relative"
Unchecking the "Prefer Margin Relative" checkbox will keep you from getting into the situation where you get this warning.
If you are like me and you built an entire app with constraints before realizing the problem, then things are a bit tougher because Xcode will not easily tell you which constraints are a problem.
In order to avoid rebuilding all of my constraints, I resorted to looking at the actual .storyboard file and I looked for constraints like this:
<constraint firstItem="vId-..." firstAttribute="top" secondItem="In7-..." secondAttribute="topMargin" id="C0H-..."/>
Notice "topMargin". The attributes ending in "Margin" cause the warning. I went through and identified the constraints in the file this way, then I removed and re-created them in IB. After that, this warning went away.
I suspect this should also resolve some inconsistencies between iOS 7 and iOS 8 constraint handling, although I am still encountering some differences in behavior, even after addressing all Xcode warnings.
I'm currently in the same situation as I'm creating an app in Xcode 6 that targets iOS7 and 8. That warning appears because the constraints relative to the margin aren't available in iOS7, but they are created by default in Xcode 6.
You can absolutely go back and edit the constraint to not use that 'Relative to margin' feature as suggested by the other answers to this question.
When creating new constraints, I hold down the Option key when choosing which kind of constraint to create. This gives me the ability to create a constraint that's not based on the margin right away so I don't have to go back and fix it afterwards.
Xcode 6 creates constraints based on relative margins by default.
So, if you want to force remove all baselines attributes and don't want to search all bad constrains in Interface Buidler, to support iOS 7, I can recommend this way
To find and remove all dummy strings with "Baseline" in constraints you can do this:
Close Xcode
Open your stroyboard file in your favorite text editor, that supports regexp.
Find and remove from storyboard file all strings by pattern: .*"baseline".*\n
Now save file and open it in Xcode
Fix all appeared misaligns: find all warnings and press "Update constraints for all views" to save original position of all views.
Profit!
UPD:
I found that "baseline" constraints causes crashes also, but Xcode doesn't show any warnings about these constrains!
To fix it - remove from storyboard file all strings by pattern: .*"baseline".*\n
I took a non programmer approach.
I knew which view controler was causing the 8.0 margin message. So, I went to my constraint list. I had 33. I've remove every one that was causing the 8.0 margin message. I went down to 20 (So 11 was problem).
Select 32 over 33 delete and see the result. Select 31 over 33 delete and so on ... Naturally when the message still there ... delete the problematic one.
So it took me 5 minutes to resolve the error message.
Other constraint messages did appear but that's not a big deal.
Ok than, redo and resolve step by step the constraint messages but this time check that all the constraint you add don't provoke the reappearing of the 8.0 margin message. If so, undo and take an other strategy when adding constraints. There's always an other way to add a constraint that work.
That's not what is proposed by Xcode but it will do the job.
At the end, your done.
If you have more than one view controller, and don't know witch one is causing the 8.0 margin message, try to isolate each view controller. May be in a separate test project with a copy and paste or deleting all the other view except one and se the result.
Using the "Create Snapshot" in the file menu can help you if something goes wrong.
Suppressing the warnings: I went through all IB constraints and deleted all that said "First Baseline...". This made all of these warnings go away. However, IB will reintroduce the warnings if you "Add missing constraints" or "reset to suggested constraints".
Possible cause: From a fresh Xcode 6.1 project, I copy/pasted ViewControllers in Storyboard (lazily), using "reset to suggested constraints". Then changed the project target from 8.0 to 7.1. This caused the warnings to pop up. I noticed that the warnings only occurred on certain of my ViewControllers, which I believe were the ones I copied/pasted in Storyboard.
Suggestion: If targeting 7.1, set it up front before using IB. Don't copy/paste view controllers in Storyboard. And be wary of "new warnings" when working within IB, so hopefully we can confirm the cause of this annoyance.

Resources