Getting wrong orientation

蹲街弑〆低调 提交于 2019-12-06 14:54:38

问题


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;
}

回答1:


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.




回答2:


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




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/4560545/getting-wrong-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!