-1

我有一个以 aUIViewController作为根视图控制器的应用程序(不是 aTabBarNavigationController应用程序!)。这个应用程序是通用的。iPhone 应该始终是纵向的,iPad 应该始终是横向的。

我尝试了以下方法,但我认为这是 iOS 5 代码,因为它没有在 iOS 6 中调用:

    - (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    else
    {
        return (interfaceOrientation == (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight));
    }
}

任何帮助表示赞赏!

4

1 回答 1

0

这是 iOS 6 的代码集。它使用掩码。如果它是针对整个 iPhone 一个方向和 iPad 一个方向,那么在项目级别,您可以通过取消选择与您不想要的方向相关的按钮来设置它。也就是说,如果 iPhone 中的所有视图都将相同,并且对于 iPad,它也适用。如果您想使用代码执行此操作,则以下操作将完成:

- (BOOL) shouldAutorotate
{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft   | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

只需采用您不想使用的方向即可。如果您需要更多帮助,请告诉我。

于 2013-03-18T20:43:26.530 回答