【问题标题】:change device orientation compatible for ios6 and ios5更改与 ios6 和 ios5 兼容的设备方向
【发布时间】:2013-08-22 06:12:29
【问题描述】:

我需要:以编程方式将设备从纵向旋转到横向,兼容 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
        // ???
    }

【问题讨论】:

    标签: ios5 ios6 uiviewcontroller uiinterfaceorientation


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-16
      • 1970-01-01
      相关资源
      最近更新 更多