'UISplitViewController wrong value for the frame of PrimaryViewController view

I have a UISplitViewController with 2 custom viewControllers. When I go to setup the primary view controller and want to get the frame of the view, it gives me a totally odd value and when using it to draws the content partly off screen.

Here is my setup in storyboard

enter image description here

Here is the code for drawing the primary viewController

override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = UIColor.yellow
}


override func viewDidAppear(_ animated: Bool) {
    print( "view bounds:\(view.frame)")
    let testView = UIView(frame: view.frame.insetBy(dx: 30, dy: 30 ))
    testView.backgroundColor = UIColor.black.withAlphaComponent(0.3)
    view.addSubview( testView )
    
}

Here is an image of what is drawn, The two inset rects are expected to be in the bounds of the view.

enter image description here

Oddly enough when I go to inspect the view hierarchy it shows an odd layout for the PrimaryViewController

enter image description here

And here is a link to a simple test project:

enter link description here

Any Ideas of how to get the correct frame for the view for the primaryViewController.

Thanks
Reza



Solution 1:[1]

The primary column contains a 100-pt offscreen buffer which can be read by calling view’s safeAreaInsets.left. This will return a value of 100, and adjusting the frames using this value resolves this issue.

Solution 2:[2]

I was experiencing the same problem, but it was solved by restricting all the elements that would enter the primary view controller based on the safeayoutguide

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 reza23
Solution 2 hellya