更改与ios6和ios5兼容的设备方向



我需要:通过编程将设备从纵向旋转到横向,兼容iOS6和iOS5。
问题:我无法在ios6上使用[UIDevice setOrientation]函数。

我所拥有的:iOS6的代码:

- (BOOL) shouldAutorotate
{
    return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

iOS5的代码:

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

因此,我需要编写在iOS5上旋转的代码:

 -(void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        // [[UIDevice currentDevice] setOrientation] - I cannot use it
        // ???
    }

我通过设置状态栏方向来实现这一点,尝试在代码中执行:

[[sharedApplication] setStatusBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

当您需要纵向模式时,将状态栏设置为setStatusBarHidden:NO,并再次将状态栏方向设置为纵向UIInterfaceOrientationPortrait

最新更新