1

UITabBarController回転の問題を処理するためのサブクラスがあります。

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

-(NSUInteger)supportedInterfaceOrientations{
    return [self.selectedViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate{
    return YES;
}

そして今UIViewControllertabbatcontroller私は新しいものを提示しUIViewControllerます:

MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC];

radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainNav animated:YES];

そして、この新しいナビゲーションでは、自動回転を無効にして縦向きのみを許可したい:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate{
    return NO;
}

しかし、回転はまだ機能しており、画面を回転するとアプリが横向きの画面になります。この問題を解決するにはどうすればよいですか?

4

1 に答える 1

1

UINavigationControllerまた、サブクラス化して、サブクラスに次のコードを配置する必要があります。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
    return NO;
}

次に、サブクラスのインスタンスを初期化します。

MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
MYSubclassedNavigationController *mainNav = [[MYSubclassedNavigationController alloc] initWithRootViewController:mainVC];

radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainNav animated:YES];
于 2013-05-27T13:36:43.707 に答える