开发者

Getting wrong orientation

开发者 https://www.devze.com 2023-02-01 13:05 出处:网络
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 func开发者_开发知识库tion, I get portrait orientation.

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 func开发者_开发知识库tion, 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;
}


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.


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消