Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c StatusBaroOrientation不';我不能给出正确的答案_Objective C - Fatal编程技术网

Objective c StatusBaroOrientation不';我不能给出正确的答案

Objective c StatusBaroOrientation不';我不能给出正确的答案,objective-c,Objective C,当按下按钮时,我正在检查设备是否处于横向模式或纵向模式,并显示以下代码: orientation = [[UIApplication sharedApplication]statusBarOrientation]; - (void)buttonclick { if (orientation == UIInterfaceOrientationPortrait) { NSLog(@"port"); } else { NSLog

当按下按钮时,我正在检查设备是否处于横向模式或纵向模式,并显示以下代码:

orientation = [[UIApplication sharedApplication]statusBarOrientation];

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


在这种情况下,即使模拟器处于纵向模式,它也会记录着陆。怎么了?

您应该在方法内部设置方向:

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

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