I have instantiated a UINavigationController
with a custom view controller. Its view contains a button that, when tapped, will have the navigation controller push the view of a different custom view controller into view:
@IBAction func showVC(sender: AnyObject) {
let vc = MyOtherViewController()
navigationController?.pushViewController(vc, animated: true)
}
In MyOtherViewController's
viewWillAppear() function, I see that the view has not be resized to fit in the view hierarchy.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
print("view: \(view)")
}
The output from the print()
function is:
view: <UIView: 0x7f9432719bd0; frame = (0 0; 600 600); autoresize = W+H; layer = <CALayer: 0x7f9432717cc0>>
As you can see, the size of the view is still 600 x 600
at this point, which is the original size from the .xib file. I haven't adjusted the size of the view in the .xib because the view will be shown on various iPhone and iPad displays.
My dilemma is that I need the final dimensions of the view as I need to construct some NSLayoutConstraints
based on the width of the view.
What is the recommended approach for having the view resized? Is it wrong to expect the view to be resized by the time -viewWillAppear() is invoked?