仅状态栏在 iPhone 横屏模式下旋转

7

我有一个仅支持竖屏的ViewController。然而当设备旋转时,状态栏会旋转到横屏模式,但是视图仍然保持竖屏模式。我想要禁止状态栏的旋转。这个问题只在IOS7中出现。

// Overridden function to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        // iPhone: support only upright portrait
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    else 
    {
           // iPad: any orientation is OK
            return YES;
     }
}

// For iOS6.0 Rotate
- (BOOL)shouldAutorotate
{
    return NO;
}

2
自iOS 6起,方法“-shouldAutorotateToInterfaceOrientation”已被弃用,您需要使用“-supportedInterfaceOrientations”代替。 - medvedNick
1
提醒一下 - 我在一个干净的新单视图项目上试用了你的代码,状态栏无法旋转 (模拟器, iOS 7)。如果你的视图控制器类被继承,你可能需要检查继承链,或者在 Xcode 的项目/目标设置中检查支持的界面方向设置。 - Jai Govindani
谢谢您的回复,在模拟器中一切正常,只有在设备上才出现这个问题。 - Sabareesh
2
我有同样的问题。如果我从头开始运行应用程序,它不会发生,但是如果我返回到主屏幕,然后再次进入应用程序,问题就会出现。这非常令人沮丧,因为我绝对确定在“-supportedInterfaceOrientations”中返回了正确的值。 - Trebor
1个回答

0
使用此方法将其保持为纵向视图:
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接