I have a tabbar application. And the item of first tab is Navigation Controller. Navigation controller has 4 items in his stack. I want to provide rotation. But in tabbar application it s the problem, that s why I created my own tabbarcontroller and override the method:
@interface RotatingTabBarController : UITabBarController
@end
@implementation RotatingTabBarController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if([self.selectedViewController isKindOfClass:[UINavigationController class]]){
BOOL f = [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
return f;
} else {
BOOL f = [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
return f;
}
}
@end
在那之后,如果我提供适当的 UI Interface 支持, 我的控制器将支持自动旋转。 但是没有我自定义的旋转塔巴控制器, 这似乎是不可能的 。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
The problem is: When I push FirstViewController in navigation controller in shouldAutorotateToInterfaceOrientation of this viewcontroller I provide only portrait orientation, but when I push SecondViewController (I provide there both portrait and landscape orientation), if current interface orientation of SecondViewController is landscape and I press back button (SecondViewController pop from stack and FirstViewController appears), the orientation of FirstViewController is landscape. But in shouldAutorotateToInterfaceOrientation method I provide only portrait orientation for him.