Autoresize all UIScrollView subviews properly on orientation change
I have:
- 1 paging scroll view at the bottom (like a panel) that is ini开发者_运维问答tially at 768x100 pixels, which is set up to stretch to 1024 when iPad rotates to landscape.
- 2 subviews, each 768x100 pixels big; one at origin 0,0, and one at origin 768,0. In portrait, the user can swipe left and right to switch between these panels.
When I rotate to landscape, the subviews stay the same size even though autoresizing is correct. They also stay at the same position, which means the right hand pane now appears 256 pixels "in" from the right.
Is there no way to fix this using autoresizing? Do I have to adjust the subviews on rotation manually?
If the interface builder approach does not work or if you have complex subviews you need to realign, then you could do this -
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
/* handle resizing here*/
}
else if(interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
}
I could be wrong, also check this
As far as I know, you have to adjust the subviews manually. Because the UIScrollView's contentSize property define the size of the view displayed for Span&Zoom. It normally does not have any relation with the container (i.e. scrollview) size.
You can use autosizing on the interface builder.
精彩评论