2

我有一个支持方向更改并相应旋转的应用程序。我听事件 UIApplicationWillChangeStatusBarOrientationNotification。现在,在加载此应用程序期间,我添加了一些视图并根据当前方向在我的应用程序中设置它们。

在 iOS 6 中,这可以正常工作,并且应用程序可以正确响应和旋转,因此用户可以在横向和纵向模式下加载,并且代码可以正常工作。

在 iOS 5 中,如果我以纵向模式加载应用程序,则应用程序工作正常,并且一旦以纵向模式完成加载,并且 UI 对齐和调整大小,它将响应横向或纵向的其他方向更改。我遇到的问题是:在横向模式下加载 iOS 5 时,在将带有 iOS 5 的设备物理放置在平面上以确保其横向时,我得到一个从横向移动到纵向的 OrientationNotification(尽管设备没有改变 )。

因此,同一实验中的另一台设备 iOS 6 可以正常加载,并且我没有收到任何奇怪的旋转更改事件,但在 iOS 5 中我确实得到了它们!

有任何想法吗?

我支持两个 iOS 的方向

- (BOOL)shouldAutorotate {
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:
                                   (UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
4

1 回答 1

2

听起来 iOS 5 认为事物应该是纵向的,如果实际上没有物理方向(即平向上或向下)而 iOS 6 没有。为了确定在重要时显示内容的方向可能值得,我在可用时使用实际设备方向,在设备平坦时使用状态栏方向。例如:

// Get a useful screen orientation.
// If the device is physically in portrait or landscape then
// that is the orientation.
// If it is not, then it is probably flat on a table and use
// the orientation of the status bar which should be set to
// the last physical orientation.
//
// screen Orientation
//------------------------------------------------------------
+ (UIDeviceOrientation) screenOrientation {
   UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
   if (orientation!=UIInterfaceOrientationPortrait
       && orientation!=UIInterfaceOrientationPortraitUpsideDown
       && orientation!=UIInterfaceOrientationLandscapeLeft
       && orientation != UIInterfaceOrientationLandscapeRight) {
       // Not known at this time.  Use the status bar orientation
       orientation = [[UIApplication sharedApplication] statusBarOrientation];
   }
    return orientation;
}

我不确定这是否会直接帮助您,但也许在您的通知处理程序中,您可以查看实际的状态栏方向是什么。或者,通知的时间和状态栏方向的变化可能无法实现。

于 2013-03-01T17:37:25.507 回答