Advertisement
mpokhylets

FB7664598

Apr 15th, 2020
1,194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.85 KB | None | 0 0
  1. // Simulator: iPhone 11 Pro (11.3)
  2. // Xcode: 11.3.1 (11C505)
  3. import UIKit
  4.  
  5. @UIApplicationMain
  6. class AppDelegate: UIResponder, UIApplicationDelegate {
  7.     var window: UIWindow?
  8.  
  9.     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  10.         let window = UIWindow()
  11.         let vc = UIViewController()
  12.         window.rootViewController = vc
  13.         vc.view.backgroundColor = .white
  14.  
  15.         let label = UILabel()
  16.         label.numberOfLines = 0
  17.         label.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
  18.         label.translatesAutoresizingMaskIntoConstraints = false
  19.         vc.view.addSubview(label)
  20.  
  21.         NSLayoutConstraint.activate([
  22.             vc.view.centerXAnchor.constraint(equalTo: label.centerXAnchor),
  23.             vc.view.centerYAnchor.constraint(equalTo: label.centerYAnchor),
  24.         ])
  25.         window.makeKeyAndVisible()
  26.         window.updateConstraintsIfNeeded()
  27.         window.layoutIfNeeded()
  28.         print(label.frame) // (-311.3333333333333, 230.0, 942.6666666666666, 20.333333333333332)
  29.  
  30.         let c = label.widthAnchor.constraint(equalToConstant: 75) // Works fine with 200, for some reason
  31.         c.isActive = true
  32.         window.updateConstraintsIfNeeded()
  33.         window.layoutIfNeeded()
  34.         print(label.frame) // (122.66666666666669, 77.66666666666666, 75.0, 324.6666666666667)
  35.         c.isActive = false
  36.         window.updateConstraintsIfNeeded()
  37.         window.layoutIfNeeded()
  38.  
  39.         // Expected: (-311.3333333333333, 230.0, 942.6666666666666, 20.333333333333332)
  40.         // Actual: (122.66666666666669, 77.66666666666666, 75.0, 324.6666666666667)
  41.         print(label.frame)
  42.  
  43.         self.window = window
  44.         return true
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement