I have a tabBarController with 4 views. I wanted the second view to rotate, so i've added
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
to all my 4 viewControllers. Now every view can rotate, and this is good.
The second view is working fine on rotation, it handles the resizing and redrawing of his contents very well. (for now the other views rotate but don't update their contents, i will work on it)
The problem is that, if i stay in the first view, rotate the phone, and then move to the second view, all the contents are re开发者_Python百科sized in a strange way.
For example, i have a scrollView on the second view, covering all the screen. When i rotate the phone while staying in the second view, it resize the scrollview to fit the landscape screen, everything ok. But if i rotate the phone staying in the first view (or in the third or in the fourth) the scroll view become small, less then half of the screen.
For resizing and redrawing the contents i'm using:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation]; }
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight) {
sfondo.frame = CGRectMake(0, 0, 480, 260);
scrollView.frame = CGRectMake(0, 0, 480, 250);
scrollView.contentSize = CGSizeMake(480,1000);
for (int i=0; i<3; i++) {
[[grafici objectAtIndex:i] landscapeMode:TRUE];
}
}
else if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown) {
sfondo.frame = CGRectMake(0, 0, 320, 411);
scrollView.frame = CGRectMake(0, 0, 320, 411);
scrollView.contentSize = CGSizeMake(320,1100);
for (int i=0; i<3; i++) {
[[grafici objectAtIndex:i] landscapeMode:FALSE];
}
}
}
I found out that the issues were raising from the fact that i had set my scrollview and other things from Interface Builder.
Doing this programmatically solved my problem!
精彩评论