UIViewController.setOverrideTraitCollection(_:forChildViewController:) reports wrong previous traits to child views

Originator:zach
Number:rdar://32660345 Date Originated:08-Jun-2017 03:26 PM
Status:Open Resolved:false
Product:iOS + SDK Product Version:iOS 11.0 Beta 1 (15A5278f)
Classification:Other Bug Reproducible:Always
 
Area:
UIKit

Summary:
See title. A subview in the view of a child view controller updated via `setOverrideTraitCollection` is given an incorrect `previousTraitCollection` when `preferredContentSizeCategory` is involved. Since many implementations (including those backing `UILabel.adjustsFontForContentSizeCategory` et. al.) check for duplicate content size categories in order to not do duplicate work, these subviews never get the effect of the override trait collection.

Steps to Reproduce:
See attached sample code.

1. Set up a view controller containing another view controller using "Container View" in the Interface Builder.
2. In the child view controller, set up a `UILabel` with `adjustsFontForContentSizeCategory = true`.
2. Call `setOverrideTraitCollection` from the parent view controller.

Expected Results:
I can drag the slider in the sample project to resize the label.

Observed Results:
The label does not automatically update its font size from a custom event.

Version:
iOS 11.0 Beta 1 (15A5278f) / Xcode Version 9.0 beta (9M136h)

Also occurs on iOS 10.3 (14E8301)

Notes:
A workaround was not forthcoming. The root view of a UIViewController propagates trait notifications down asynchronously, after the view controller has re-cached the new trait collection as its "previously notified" trait collection.

Configuration:
N/A

Comments

Added attachment

https://drive.google.com/file/d/0B3FglI-wO7EqNHFyWERxSFNrZEk/view?usp=sharing


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!