UIDeviceOrientationDidChangeNotification返回的设备方向不准确

edd*_*ddy 4 iphone

我正在收听UIDeviceOrientationDidChangeNotification,以便根据设备的方向调整我的UI.

问题是我从通知中获得的设备方向似乎不准确.如果我从纵向和垂直方向开始使用手机(就像用它拍照一样),我从通知中获得的方向是正确的.随着手机的倾斜度接近水平(如平放在桌面上),方向切换到横向.这种情况发生在电话实际上在桌子上平放之前.这根本就没有将手机转向风景.就好像它偏爱景观一样.

使用其他应用程序(如邮件)时,我看不到同样的行为.一旦确定你已经进入新的方向,邮件似乎只会切换方向.

任何帮助非常感谢.

谢谢,

edd*_*ddy 9

我发现了我的问题.

在viewWillAppear我有:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(didChangeOrientation:) name: UIDeviceOrientationDidChangeNotification object: 
     [UIDevice currentDevice]];
Run Code Online (Sandbox Code Playgroud)

这是通知处理程序:

- (void) didChangeOrientation: (id)object {
    UIInterfaceOrientation interfaceOrientation = [[object object] orientation];
    //DLog(@"val is %i", interfaceOrientation);
    if (interfaceOrientation == UIDeviceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationLandscapeRight || interfaceOrientation == UIDeviceOrientationPortrait) {
    [self orientInterface:interfaceOrientation];
}
Run Code Online (Sandbox Code Playgroud)

通过检查方向是两个风景中的一个或两个肖像,我忽略了UIDeviceOrientationFaceUp和UIDeviceOrientationFaceDown方向.这样,将手机设置为这两个方向之一就不会对我的界面方向产生影响.

我的问题是我没有考虑faceUp和faceDown,而是在一个假定为landscape的else语句中处理它们.