In my App Delegate I overrode shouldAutorotateToInterfaceOrientation in my UITabBarController (don’t worry – I didn’t subclass it! 😉 ) . I did it like this:
(Bottom of AppDelegate.h):
@interface UITabBarController (MyApp)
@end
(Bottom of AppDelegate.m):
@implementation UITabBarController (MyApp)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if(self.selectedIndex==4)
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
else
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
Currently I have it so that when I go onto a specific tab (index 4), it will not rotate to landscape when the device is rotated (which is what I want). Although the problem is that if the application is already landscape and you tap onto that view, it is landscape (I want it to remain portrait). (NOTE: The app rotates fine if I let it to, so working with shouldAutorotateToInterfaceOrientation shouldn’t really fix the problem (or it might))
I’ve found this UITabBarController delegate method:
- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)tabViewController {
NSUInteger indexOfTab = [theTabBarController.viewControllers indexOfObject:tabViewController];
if (indexOfTab == 4) {
//FILL GAP HERE!
}
}
I’ve tryed this:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
But it only rotates the status bar – not the whole app. Is there some method (or anything) in UITabBarController that’ll rotate it to portrait to fill in the gap above?
Sorry if it isn’t too confusing for anyone.
Used
transformandsetStatusBarOrientation– although it has some side effects (will have to do for now).