Reputation: 9082
In interface builder I have created a UIVIew (the view of a UIViewController) containing a UIScrollView. The UIScrollView is set up in a way that it will resize depending on the orientation of the iPad.
When I launch the application in portrait mode, the view initially has a width and height of the portrait orientation. It is only after I start interacting with the app that the view suddenly adjusts to the "correct" orientation.
Basically, my question is why the frame and bounds of the UIScrollView (and the UIView for that matter) remain as if the device was in portrait mode? I have seen several threads on the net about this, but none of them really gave me the answer I am looking for.
The weird thing is that when I give the UIScrollView a vivid background color (so I can see its dimensions), it has the correct proportions, but the frame and bounds are "incorrect".
Upvotes: 1
Views: 301
Reputation: 9082
I got it figured out and it surprised me a bit. First, I noticed that the size of the scroll view was correct (that is, matching the orientation of the device) and that is the reason I based the content size of my scroll view on the bounds of the scroll view (because it turned out that it was an incorrect content size that caused all the trouble).
This all works fine, but the caveat is that the size of the scroll view (and any other view for that matter) is adjusted to the orientation of the device NOT in the viewDidLoad method, but in the viewWillAppear method. (Just to be clear, with the prior I don't mean that this actually happens IN the viewDidLoad method).
So, I wrongly set the content size of the scroll view in the viewDidLoad method, but at that moment the size of the scroll view was "not correct" yet (with "not correct" I simply mean that depending on the orientation of the device, it was not adjusted to the orientation of the device). What I did to solve the issue was moving my method that set the content size of my scroll view to the viewWillAppear method.
It sounds easy (and it is), but it took me some time to figure this out. I hope this helps anyone with a similar issue in the future.
Upvotes: 2