1) Access the height in viewDidAppear lifecycle method
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
//access the view size here.
}
2) Use Dispath Queue’s Main queue
DispatchQueue.main.async {
//access the size here..
}
3) Call layout update methods before access the size as below
func getSizeOFTheView() {
self.setNeedsLayout()
self.layoutIfNeeded()
//now access the view size
}
4) Override the viewDidLayoutSubViews method as below,
override viewDidLayoutSubviews() {
//access the size here...
}
There are few other ways too but i believe above mentioned points would be more helpful. you can use them as per your requirements.
Happy coding 👍