0

为什么 UIInterfaceOrientation 总是回到右边?
当我完成旋转时,总是在右边结束,为什么?
PS:我只想风景

这里是代码

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    switch (interfaceOrientation)
    {
       case UIInterfaceOrientationLandscapeLeft:
          NSLog(@"Is Left");
       case UIInterfaceOrientationLandscapeRight:
          NSLog(@"Is Right");
       default: ;
    }

    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    switch (fromInterfaceOrientation)
    {
        case UIInterfaceOrientationLandscapeLeft:
          NSLog(@"From Left");
        case UIInterfaceOrientationLandscapeRight:
          NSLog(@"From Right");
        default: ;
    }
}

这是日志

2012-08-23 17:45:28.074 Simulador 360[323:707] Is Right
2012-08-23 17:45:28.126 Simulador 360[323:707] Is Right
2012-08-23 17:45:28.131 Simulador 360[323:707] Is Left
2012-08-23 17:45:28.132 Simulador 360[323:707] Is Right
2012-08-23 17:45:28.138 Simulador 360[323:707] Is Left
2012-08-23 17:45:28.140 Simulador 360[323:707] Is Right
2012-08-23 17:45:31.160 Simulador 360[323:707] Is Right
2012-08-23 17:45:31.167 Simulador 360[323:707] Is Right
2012-08-23 17:45:31.977 Simulador 360[323:707] From Left
2012-08-23 17:45:31.980 Simulador 360[323:707] From Right
2012-08-23 17:45:35.684 Simulador 360[323:707] Is Left
2012-08-23 17:45:35.687 Simulador 360[323:707] Is Right
2012-08-23 17:45:35.691 Simulador 360[323:707] Is Left
2012-08-23 17:45:35.693 Simulador 360[323:707] Is Right
2012-08-23 17:45:36.502 Simulador 360[323:707] From Right
4

1 回答 1

0

您的陈述中缺少breaks 。switch如果不调用break,执行将继续到下一个案例,因此如果您的案例如果界面方向评估为左,则将执行左和右案例块。

break通过在每个案例的末尾插入来解决此问题:

switch (interfaceOrientation)
{
   case UIInterfaceOrientationLandscapeLeft:
      NSLog(@"Is Left");
      break;
   case UIInterfaceOrientationLandscapeRight:
      NSLog(@"Is Right");
      break;
   default: ;
}
于 2012-08-23T21:14:54.083 回答