当设备在桌面上是平的时,willRotateToInterfaceOrientation不起作用

时间:2014-03-13 11:57:20

标签: ios7 rotation device

我正在使用这段代码来检测方向的变化并切换视图:

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
    [self performSegueWithIdentifier:@"PORTADA-PORTADAH" sender:self];
    }
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    [self performSegueWithIdentifier:@"PORTADA-PORTADAH" sender:self];
    }
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
    nil;
    }
else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    nil;
    }

}

它工作正常,但当设备在桌子上是平的时,它根本不起作用。这只是提升15度或20度的设备(ipad)的问题,但我的雇主对此不满意。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

当设备与地面平行时,它不会调用4个方向中的任何一个。或平放在桌子上。它会面朝上,面朝下。通过使用以前的方向,我们需要使用面朝上和面朝下的最新方向来管理起源。

答案 1 :(得分:0)

仅当陀螺仪检测到重力矢量的差异时,才会更改iOS中的界面方向。当设备平放时,即使围绕y轴旋转设备,也无法知道用户相对于设备的位置。当重力矢量发生变化时,假设用户与该矢量平行,因此很容易猜到。

TL; DR - 不太可能。