11
22import UIKit
33
4+ func delay( _ delay: Double , closure: @escaping ( ) -> ( ) ) {
5+ let when = DispatchTime . now ( ) + delay
6+ DispatchQueue . main. asyncAfter ( deadline: when, execute: closure)
7+ }
8+
9+
410class ViewController : UIViewController {
511
612 var didSetup = false
@@ -12,19 +18,36 @@ class ViewController: UIViewController {
1218
1319 let mainview = self . view!
1420
15- let v = UIView ( )
21+ // ok, I proved what I wanted to prove: it really _is_ whether it's a vc's main view
22+ // let vc = UIViewController()
23+ // self.addChildViewController(vc)
24+
25+ let v = UIView ( )
26+ // let v = vc.view!
1627 v. backgroundColor = . red
1728 v. translatesAutoresizingMaskIntoConstraints = false
1829
1930 mainview. addSubview ( v)
2031
32+ // vc.didMove(toParentViewController: self)
33+
2134 NSLayoutConstraint . activate ( [
2235 NSLayoutConstraint . constraints ( withVisualFormat: " H:|-(0)-[v]-(0)-| " , metrics: nil , views: [ " v " : v] ) ,
2336 NSLayoutConstraint . constraints ( withVisualFormat: " V:|-(0)-[v]-(0)-| " , metrics: nil , views: [ " v " : v] )
2437 ] . flatMap { $0} )
2538
2639 // experiment by commenting out this line
27- v. preservesSuperviewLayoutMargins = true
40+ // v.preservesSuperviewLayoutMargins = true
41+ delay ( 1 ) {
42+ // print(mainview.layoutMargins)
43+ // 20 on iPad Pro large
44+ // 20 on iPhone 6s Plus
45+ // 20 on iPad Air 2
46+ // 16 on iPhone 5s
47+ // 16 on iPhone 6s
48+ print ( v. layoutMargins)
49+ // print(v.window!.layoutMargins)
50+ }
2851
2952 let v1 = UIView ( )
3053 v1. backgroundColor = . green
0 commit comments