iOS 6 用のアプリで別の問題に遭遇しました。ウィンドウの rootviewcontroller 用の UITabBarController があり、この tabbBarController に 4 つの uiviewcontrollers があり、そのうちの 2 つが「UIInterfaceOrientationMaskPortrait」を表示するだけで、他の 2 つが「 UIInterfaceOrientationMaskLandscape」、問題は、「UIInterfaceOrientationMaskPortrait」に表示されるものからUIInterfaceOrientationMaskLandscapeである他のviewControllerにタップすると、新しく選択されたビューコントローラーはまだ「UIInterfaceOrientationMaskPortrait」ですが、デバイスを回転させると、新しく選択されたビューコントローラー「UIInterfaceOrientationMaskLandscape」に回転すると……
別のviewControllerをタップしたときにtabbarviewcontrollerを自動回転させる方法はありますか?
以下は私のコードです: 1. TR_UITabViewController.m で UITabBarController のサブクラスを既に使用していました。
-(NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
appdelegate.m にもメソッドを実装します
(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ NSUInteger 方向 = UIInterfaceOrientationMaskAllButUpsideDown;
if(self.window.rootViewController){ UITabBarController *presentedViewController = (UITabBarController *)self.window.rootViewController; UIViewController * currentVC=presentedViewController.selectedViewController;
NSLog(@"currentVC info:%@",[currentVC description]); if ([currentVC isKindOfClass:[UIViewController class]]) { orientations = [currentVC supportedInterfaceOrientations]; // self.tabBarController.=[currentVC supportedInterfaceOrientations]; } else if([currentVC isKindOfClass:[UINavigationController class]]) { UINavigationController * nvc=(UINavigationController*)currentVC; UIViewController * vc=nvc.topViewController; orientations = [vc supportedInterfaceOrientations]; }
}
オリエンテーションを返します。}
3. 最後に、各ビュー コントローラーに以下の 2 つのメソッドを記述しました - (BOOL) shouldAutorotate ; & - (NSUInteger) supportedInterfaceOrientations
世界では、誰かが tabbarviewcontroller で別のビュー コントローラーをタップしたときに方向を強制的に変更する方法を知っていますか?