viewDidAppear does not update the views to the actual measurements according to the device

0

The first time I install a viewController, the measurements of its storyboard views update me to the real ones of the device.

So if I make a self.view.frame.width inside viewDidAppear it gives me the value of that measure adapted according to the device.

But if I delete the view and re-instantiate it to call it again then self.view.frame.width always gives me the same fixed value of the view according to the storyboard that I have.

How do I make it behave like the first time and give me the measures adapted according to the device?

    
asked by Popularfan 06.03.2018 в 22:15
source

2 answers

1

If you are using storyboards, in the viewWillAppear and viewDidAppear methods, when you call self.view.frame it is possible that the size is 0 or it can also be the size of the View Controller of the storyboard, it is advisable to use the viewDidLayoutSubviews method, this it is called after applying certain restrictions of autolayout and it is sure that in this method the size of your frame is the one of the device.

    
answered by 09.05.2018 / 00:45
source
1

Use viewDidLoad () since it is called only when the view is created, that is, the first time. Anyway, if what you want are the measures of the device you have to ask for them and not for the ones in the view:

UIScreen.main.bounds.width
UIScreen.main.bounds.height

If you do not put neither width nor height it returns both.

    
answered by 20.04.2018 в 09:47