私はタブバーアプリケーションを持っています。そして最初のタブの項目はNavigation Controllerです。ナビゲーション コントローラーのスタックには 4 つのアイテムがあります。ローテーションを提供したい。しかし、タブバーアプリケーションではそれが問題です。そのため、独自のタブバーコントローラーを作成し、メソッドをオーバーライドします。
@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
その後、適切な UIInterfaceOrientation サポートを提供すると、コントローラーは自動回転をサポートします。しかし、私のカスタム RotatingTabBarController がなければ、それは不可能に思えます
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
問題は次のとおりです。このビュー コントローラーの shouldAutorotateToInterfaceOrientation でナビゲーション コントローラーの FirstViewController をプッシュすると、縦向きのみが提供されますが、SecondViewController をプッシュすると (縦向きと横向きの両方を提供します)、SecondViewController の現在のインターフェイスの向きが横向きであり、押し戻す場合ボタン (SecondViewController がスタックからポップされ、FirstViewController が表示されます)、FirstViewController の向きはランドスケープです。しかし、shouldAutorotateToInterfaceOrientation メソッドでは、私は彼に縦向きのみを提供します。