2012-03-20 49 views
1

我做了一些研究,但似乎无法找到答案,让我的navigationController的rootViewController在启动时正确无误。我原来的问题在这里:launch orientation of iPad is incorrect for landscape orientation (upside down)Force UIViewController orientation

在我的info.plist中,我将它设置为支持两种风景方向。如果我将我的rootViewController更改为:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// return UIInterfaceOrientationIsLandscape(interfaceOrientation); // original that does not work 
    return YES; 
} 

然后我的应用程序以正确的方向启动。但是,我不想支持肖像模式。我只想支持风景模式。我想我可能会迫使取向,用做这样的事情防止它切换到肖像模式:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     UIDeviceOrientation orientation = UIInterfaceOrientationLandscapeLeft; 
     [UIApplication sharedApplication].statusBarOrientation = orientation; 
    } 
    else { 

    } 

但这并不阻止应用旋转到肖像模式。是否有可能强制方向?为了使启动方向正确(仅风景模式),是否还有其他事情需要我去做?谢谢!

回答

1

我刚刚创建了一个示例项目,将支持的界面方向(iPad)设置为左横向和右横向(在info.plist中)。

然后我用:

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

,它工作正常。它被迫景观,不管我如何旋转它。

您是否有任何其他视图控制器可见,可能会返回YES到所有方向?这可能会混淆它。

+0

因为我在我的AppDelegate中使用UINavigationController,这是一个问题吗? – Crystal 2012-03-20 17:50:13

+0

只要在UINavigationController中使用的所有其他视图控制器具有相同的shouldAutorotate策略,就不会有问题。 – bandejapaisa 2012-03-21 09:15:34

+0

嗯,我仍然有问题。当我的应用第一次启动时,我必须根据需求显示一个模式表单和一个UIAlertView。基本上这样,其中tvc是我的viewController我模式显示:'tvc.modalPresentationStyle = UIModalPresentationFormSheet; tvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizo​​ntal; [self presentModalViewController:tvc animated:YES];'。此ViewController的shouldAutoRotate也设置为返回UIInterfaceOrientationIsLandscape(interfaceOrientation)。这个视图控制器是否会导致它启动不正确? – Crystal 2012-03-21 21:49:46