Wilhelm Michaelsen
Wilhelm Michaelsen

Reputation: 663

StatusBarOrientation doesn't give correct answer

I'm checking if the device is in landscape mode or in portrait when a button is pressed with this code:

orientation = [[UIApplication sharedApplication]statusBarOrientation];

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


In this case it logs land, even thought the simulator is in portrait mode. What's wrong?

Upvotes: 0

Views: 75

Answers (1)

Martin Gordon
Martin Gordon

Reputation: 36389

You should set orientation inside your method:

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

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

}

Upvotes: 1

Related Questions