如何在IOS中修复视图控制器的特定方向

时间:2013-04-19 13:09:30

标签: iphone ios objective-c ipad screen-orientation

我正在开发一款iPad应用。它是在popover中捕获图像并在下一个视图中全屏裁剪图像。这里包含以下屏幕

1)LoginViewContoller(需要所有方向),

2)SplitViewController(需要所有方向),`

3)ImageCropViewController(仅需横向景观),

4)SettingsViewController(需要所有方向)。

ImageCropViewController我正在编写以下代码:

- (BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

我正在准确定位。但它也会影响LoginViewController'sSettingViewController's方向。

LoginViewControllerSettingViewController中,我正在编写以下代码

- (BOOL)shouldAutorotate
    {
        return YES;
    }

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

SplitViewController导航到ImageCropViewController时,我发起的ImageCropViewControllerrootViewController

在plist中,我支持这样的方向

enter image description here  我用Google搜索了一下。并整合了可用的代码。但我没有找到任何解决方案。请帮我。它真的杀了我的时间。

1 个答案:

答案 0 :(得分:0)

这是我在iPhone项目上设置的方式,但它不应该与你的不同:

首先,确保您的项目支持所有您想要的方向:

Supported Interface Orientations

然后,在SplitViewController,ImageCropViewController和SettingsViewController上覆盖这些方法:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

最后,在ImageCropViewController上覆盖这些方法:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

让我知道它是否有帮助!