Getting wrong orientation

2019-04-16 20:56发布

I am having an issue in my application which drives me mad. In my application, I rotate the simulator to the landscape mode, but in my below function, I get portrait orientation.

What is the problem here? Please help me out.

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
  if ( interfaceOrientation == UIInterfaceOrientationPortrait || 
  interfaceOrientation ==    UIInterfaceOrientationPortraitUpsideDown )
  {
    NSLog(@" portrait orientation");
  }
  else
  {
    NSLog(@"Landscape"); 
  }
 return YES;
}

4条回答
叼着烟拽天下
2楼-- · 2019-04-16 21:34

Why you did't return a BOOL value? YES or NO to tell the OS that you're gonna handle corresponding orientation events.

查看更多
疯言疯语
3楼-- · 2019-04-16 21:37

The method returns BOOL, you have to return either YES or NO

查看更多
forever°为你锁心
4楼-- · 2019-04-16 21:44

First set the orientation value is the method

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
NSLog(@"shouldAutorotateToInterfaceOrientation called...");
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIDeviceOrientationPortraitUpsideDown) 
        defaultOrientation = 0;
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        defaultOrientation = 1;
    [self setTheOrientation];
    return YES;

}

Now set the values of the coordinates which you require according to the boolean values in the setTheOrientation method.

查看更多
男人必须洒脱
5楼-- · 2019-04-16 21:54

If you want portrait mode then add return TRUE in if clouse and If you want landscape then add return TRUE in else clouse and if you want both mode then just type return TRUE in shouldAutoRotate clouse

查看更多
登录 后发表回答