为什么[UIApplication sharedApplication] .statusBarOrientation返回错误的值

时间:2013-03-18 03:49:44

标签: iphone uiinterfaceorientation

您好我的应用程序中我想知道statusbarorientation值。为此我使用[UIApplication sharedApplication].statusBarOrientation方法。实际上这种方法必须返回4表示横向,2表示potrait模式。但是这种方法以相反的方式返回值。景观2和potrait 4的手段。请让我知道如何解决这个问题。在supportedInterfaceOrientations方法我使用return UIInterfaceOrientationMaskAll;

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

可能是因为UIDeviceOrientationLandscapeRight分配给UIInterfaceOrientationLandscapeLeft而UIDeviceOrientationLandscapeLeft分配给UIInterfaceOrientationLandscapeRight。

原因是旋转设备需要向相反方向旋转内容。

从iOS 8开始,您应该使用UITraitCollection和UITraitEnvironment API,以及这些API中使用的大小类属性,而不是使用UIInterfaceOrientation常量或以界面方向编写应用程序。

无论如何,以这种方式采取方向对我有用。

var orientation = UIApplication.SharedApplication.StatusBarOrientation;
switch (orientation)
{
case UIInterfaceOrientation.PortraitUpsideDown:
// The device is in portrait mode but upside down, with the device held upright and the home button at the top.
case UIInterfaceOrientation.Portrait:
// The device is in portrait mode, with the device held upright and the home button on the bottom.
case UIInterfaceOrientation.LandscapeLeft:
// The device is in landscape mode, with the device held upright and the home button on the left side.
case UIInterfaceOrientation.LandscapeRight:
// The device is in landscape mode, with the device held upright and the home button on the right side.
case UIInterfaceOrientation.Unknown
// The orientation of the device cannot be determined.
}

还要考虑

  

但是,如果您的应用具有可旋转的窗口内容,则不应该   使用此方法任意设置状态栏方向。该   如果是,则此方法设置的状态栏方向不会更改   设备改变方向。