I have a TabBarController app with 4 views. I've put on all the 4 viewControllers the autorotate method returning yes :
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
Thanks to this, now when i rotate the iPhone the rotation works, and even the TabBar is rotated.
In every single view i can use the following code to update to view when the rotation occurs:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight) {
//Here i can update the view when it goes to landscape
}
else if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortra开发者_开发百科itUpsideDown) {
//Here i can update the view when it goes to portrait
}
}
The problem is that when i make the rotation, only the current displayed view is updating. If later i change view clicking on the tabBar, i see the view not updated for the new orientation.
Is there a way to make all the views being aware of the orientation changed?
Ok i found it! =D
The trick is using the function:
- (void)viewWillAppear:(BOOL)animated
Just call it in your viewControllers, and insert inside the code to update the view. Enjoy!
精彩评论