2

我有以下控制器,(我在 iPad 中选择了所有类型的方向模式)

这是我的 iPad 故事板布局

Custom NavigationController > Loading Ctrl > Main Controller.

我的自定义导航包含

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

在我的加载控制器中

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    else
        return UIInterfaceOrientationMaskPortrait;
}

supportedInterfaceOrientations 像往常一样被调用,一切似乎都很好,但是当我使用 performSegue 推动我的主控制器时

-(NSUInteger)supportedInterfaceOrientations
{
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    else
        return UIInterfaceOrientationMaskPortrait;
} 

MainController 中不再有调用。这是为什么?

4

2 回答 2

3

有一个窍门。

从应用程序中获取状态栏并旋转它。

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];

以模态方式创建、显示和关闭空视图控制器。

UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];

现在你的设备应该被迫旋转。您现在可以选择合适的视图控制器或使用导航控制器推送一个。

于 2013-09-23T11:58:03.560 回答
1
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);//choose portrait or landscape
}
- (BOOL) shouldAutorotate{
return NO;
}
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;//choose portrait or landscape, same as above
}
于 2013-09-23T12:01:41.783 回答