UIScrollView borders have not changed in "viewDidLoad" yet

I have a subclass of UIViewController whose presentation is configured in a NIB file. The view is subtitled UIScrollView.

UIScrollView processes almost its entire NIB file, but its supervisor is added as a subtitle to a much smaller view (configured in another NIB) - for example. UIScrollView is 80% of the height of its own NIB, but in the end it is only 10% of the application window height.

When I call [scrollView bounds] .size.height in the viewController viewDidLoad method, I get the height of the scrollView relative to its own NIB, and not the height that ends with the resize, as dictated by its supervisors (for example, 80% of the window height, not ten%).

If I call [scrollView bounds] .size.height later (for example, to handle the rotation event), I get the correct value.

How can I get the correct resizing initially?

+4
source share
2 answers

Have you tried to deal with it in viewWillAppear: or viewDidAppear ?

+7
source

Assuming I follow, there should be some moment after loading the view controller, on which you grab the .view and paste it into another view? If so, then the boundaries will be adjusted. You cannot get them in viewDidLoad because the view has no way of knowing what you will do with it in the future. Even if your call to insert it as a preview is the first thing you do after loading the view controller, it is a view accessory that will load the view and therefore viewDidLoad, all before you actually place the view in any location.

Since the borders have a getter and setter, it must match the encoding with the key, in which case you can use viewDidLoad to register an observer at the borders and do what you need to do when the borders change.

0
source

All Articles