iOS 10.2 (14C89): setting constraints relative to layout margins guide in designated initializer doesn't work reliably

Originator:whakkee
Number:rdar://30462133 Date Originated:Feb 10, 2017
Status:Open Resolved:no
Product:iOS + SDK Product Version:iOS 10.2 (14C89)
Classification:Other bug Reproducible:always
 
Area:
UIKit

Summary:
Setting constraints relative to layout margins guide in designated initializer doesn't work reliably. If you set the constraints of a view via code, the layout margins guide is not set properly if you initialize the view with .zero

Steps to Reproduce:
occurs if view is created via code and layout margins are set in viewDidMoveToSuperview or in traitCollection did change

also see description and additional notes

Expected Results:
layout margins guide should be set according to the layout margins

Actual Results:
layout margins are set to zero

Version:
iOS 10.2 (14C89)

Notes:
more info here: http://stackoverflow.com/a/40334423/2048599
and here: https://forums.developer.apple.com/message/93313

it works if the view is initialized with a bigger size than the layout margins guide - storyboards is using 1000.0 x 1000.0 to initialize and then it works, but it feels icky to use an arbitrary size here

Configuration:
rMBP with simulator or device - seems it doesn't matter what you use

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!