Reputation: 742
I'm currently dealing with an iphone view controller which contains a paging UIScrollView, to display multiple pages of information. My application needs to support a landscape mode, and I've been having a bit of trouble figuring out the right way to implement this.
In order to maintain view continuity, I want to resize my views manually in two steps. First, I override willRotateToInterfaceOrientation. In this method I extend the width of all my views in the paging scroll view to the width that they'll end up at in landscape mode. Then, in didRotateToInterfaceOrientation, I reduce the height of the views to fit the height of the landscape mode.
My question is, how do I determine the new width and height to resize my views? Hardcoding the exact values feels like a bad hack, and I get the sense that there must be an elegant way of solving the problem.
Upvotes: 1
Views: 360
Reputation: 33592
I'm not sure why you're doing layout in didRotateToInterfaceOrientation:, which happens at the end of the rotation. In any case, the new frame should already be set by UIViewController.
If you're going to sync things to the animation, look at willAnimateRotationToInterfaceOrientation:duration:
. According to the docs,
This method is called from within the animation block that is used to rotate the view. You can override this method and use it to configure additional animations that should occur during the view rotation. For example, you could use it to adjust the zoom level of your content, change the scroller position, or modify other animatable properties of your view.
By the time this method is called, the interfaceOrientation property is already set to the new orientation. Thus, you can perform any additional layout required by your views in this method.
Upvotes: 1