2

私は現在、4 つのタブを持つタブ バー コントローラーがあり、各タブにナビゲーション コントローラーがあるプロジェクトに取り組んでいます。これらの各ナビゲーション コントローラーには、複数のビュー コントローラーがプッシュされています。

ここや他の場所で多くの投稿を読みましたが、現在、次のことを行っています。

サブクラス化された UITabbarcontroller

- (BOOL)shouldAutorotate
{

    return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotate];

}

- (NSUInteger) supportedInterfaceOrientations
{
    return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController]supportedInterfaceOrientations];
}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

各ビューコントローラーで次のように指定すると、これは正常に機能します。

- (NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return YES;
}

これにより、予想どおりポートレートにロックされます。

しかし今、本当の問題が発生します!いずれかのタブの viewcontroller で横向きに回転するように指定すると、正常に動作しますが、タブを変更しても横向きのままであり、これは私たちが望むものではありません!

要約すると、ほぼすべてのビューを特定の向きにロックし、指定した向き (ここでは縦向き) にあるタブを変更できる方法を誰かが解決しましたか?

この投稿iOS 6 UITabBarController supported orientation with current UINavigation controllerも読みましたが、あるコメントでも「これはほとんど機能しています。問題は、タブを縦向きのみのビューに切り替えたときに既に横向きになっている場合です。縦向きに回転すると修正され、横向きに戻ることはありませんが、最初にロードするときに縦向きにする必要があります」これはここでもほとんど同じです..

4

1 に答える 1

2

私自身がこの問題を抱えていて、解決策を見つけました。きれいではありませんが、うまくいきます。

TabbarController サブクラスで、この tabbarcontroller デリゲート関数を実装します (デリゲートを設定することを忘れないでください)。

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    int selected = self.selectedIndex;
    UIViewController *con = [[UIViewController alloc] initWithNibName:@"XIBName" bundle:nil];
    [[self.viewControllers objectAtIndex:selected] pushViewController:con animated:NO];
    [[self.viewControllers objectAtIndex:selected]popViewControllerAnimated:NO];
    [[self.viewControllers objectAtIndex:selected] setDelegate:nil];
}

tabs navigationcontroller 内の uinavigationcontroller のプッシュ アンド ポップにより、tabbarcontroller は Orientations 関数を再度起動し、方向コードを正しく実装すると、目的の方向に変更されます。

詳細を説明する必要がある場合は、お気軽にコメントしてください。

よろしくモーテン

于 2012-11-30T13:27:34.550 に答える