Xcode 7.3: Interface Builder cannot resolve UIStackView layout warnings when Xcode is launched on a Hi-DPI primary display

Originator:connerk
Number:rdar://25321014 Date Originated:23-Mar-2016 03:58 PM
Status:Duplicate of 25111475 (Open) Resolved:
Product:Developer Tools Product Version:Xcode 7.3 (7D175)
Classification:Serious Bug Reproducible:Always
 
Summary:
UIStackView documentation lists simple use cases for stack view layout under Common Stack View Layouts: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIStackView_Class_Reference/index.html

The first bullet of that section describes two labels in a horizontal stack view pinned to the corner of the view, such that the stack view hugs the labels. I've reproduced that layout in a sample project and added another stack view pinned to the opposite corner. In such a basic case, Interface Builder is producing unresolvable layout warnings. I believe this has something to do with Xcode running in Hi-DPI mode.

Steps to Reproduce:
1. Install Xcode 7.3.
2. Open the attached sample project.
3. Open View.xib in Interface Builder
4. Observe that the constraints pin the left stack view 50 points from the top and left pin the right stack view 50 points from the bottom and right.
5. Observe the layout warnings. Try to resolve them by updating frames of the stack view and subviews.
6. Run the app in the simulator. Observe that layout is correct at runtime.

Expected Results:
Interface Builder should be able to resolve every warning with these constraints by updating frames.

Actual Results:
I was unable to resolve every warning. When I updated frames on one view, another view would gain new warnings.

Regression:
This bug reliably occurs when I launch Xcode after configuring my primary display at a Hi-DPI resolution. A reliable workaround is to configure my primary display with a @1x resolution before launching Xcode.
I think I observed a similar issue in Xcode 7.2.1, but I was new to stack views and thought it was my fault at the time.

Notes:
I am running OS X El Capitan 10.11.4.
My secondary display is configured for the default resolution for a MacBook Pro (Retina, 15-inch, Mid 2015), which is a Hi-DPI mode.
My primary display is a Dell p2715q configured to 1920x1080@2x, connected by DisplayPort.

Comments

WWDC 2016 labs commentary

An Apple engineer went through this with me, and noted that the root cause is conflicting content hugging priorities among subviews of the stack view. Xcode is failing to present that warning and instead plowing ahead and producing a bogus frame result. So the workaround is to ensure that your content hugging priorities are unique in the direction of the stack.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!