Incorrect Fractional Value Returned With systemLayoutSizeFittingSize In View with UIStackViews

Originator:bryn.bodayle
Number:rdar://29934398 Date Originated:1/9/17
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 10.2
Classification:Other Bug Reproducible:Always
 
Area:
UIKit

Summary:
systemLayoutSizeFittingSize is returning an incorrect fractional value sometimes with a particular view hierarchy setup using UIStackViews. The issue appears timing related because calling systemLayoutSizeFittingSize on subviews in the view hierarchy will prevent the fractional value from being returned.

Steps to Reproduce:
1. Download the sample project attached here or from this link:
https://www.dropbox.com/s/ft66zg1qnyupxop/UIStackView-Fractional-Bug.zip?dl=0
2. Launch the app in a 2x resolution simulator such as iPhone 5s
3. Notice that the systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) call on line 20 of ViewController.swift returns (1366.5, 96.0) 


Expected Results:
The systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) call on line 20 of ViewController.swift should return (1366, 96.0) which appropriately respects the constraints applied to the view.

Actual Results:
The systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) call on line 20 of ViewController.swift returns (1366.5, 96.0) an incorrect fractional value.

Version:
iOS 10.2


Notes:
I've simplified the sample project as much as possible to highlight the issue. The view setup is essentially a view with a UIStackView pinned to the edges that has a vertical axis, and center alignment with two subviews. The view then has a particular width constraint on it, 1366 width. This is the critical configuration that is producing the bug. If you change the alignment of the UIStackView to left alignment for instance, the bug will no longer present itself.

Also, if you uncomment the line of code on line 46 of TestView.swift the bug will not be reproduced.

Let me know if you have any questions.

Configuration:
iPhone & iPad simulators for @2x resolution devices
iOS 10.2
Xcode 8.2

Attachments:
'UIStackView-Fractional-Bug.zip' was successfully uploaded.

Comments


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!