StatusBarOrientation没有给出正确的答案

时间:2013-08-08 21:34:19

标签: objective-c

使用此代码按下按钮时,我正在检查设备是处于横向模式还是纵向模式:

orientation = [[UIApplication sharedApplication]statusBarOrientation];

- (void)buttonclick
{
    if (orientation == UIInterfaceOrientationPortrait)
    {
        NSLog(@"port");
    }
    else
    {
        NSLog(@"Land");
    }
}


在这种情况下,它记录着陆地,甚至认为模拟器处于纵向模式。怎么了?

1 个答案:

答案 0 :(得分:1)

您应该在方法中设置orientation

- (void)buttonClick {
  orientation = [[UIApplication sharedApplication] statusBarOrientation];

  if (orientation == UIInterfaceOrientationPortrait)
  {
    NSLog(@"port");
  }
  else
  {
    NSLog(@"Land");
  }

}