'Container view width decreases after adding safe area constraints

I have a ViewController and a container view testcontrollerViewController inside of it. I noticed that after I'm adding constraints to that container view in the storyboard (all the edges match the safe area) its width decreases a little bit, but if I remove constraints width changes back to normal. (Switches from 724px to 712px and back)

Is it a bug or am I doing something wrong?

enter image description here

I print container view width in its viewDidAppear function.

class testcontrollerViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    
    
    // Do any additional setup after loading the view.
    
    view.backgroundColor = .red
    print("container vc load \(testview.frame.width)")
}

override func viewDidAppear(_ animated: Bool) {
    print("container vc appear \(testview.frame.width)")
    print("container view safe area insets \(view.safeAreaInsets)")
}

@IBOutlet var testview: UIView!


Solution 1:[1]

In my opinion, I think because there is a gap between the superview and safearea. When you constraints the container view it relates to the safearea only - I think that is the reason the width changed above.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bewithyou