Ios 7中的定位问题?

时间:2013-11-06 15:01:26

标签: iphone ios5 ios6 ios7

您好我正在开发iphone应用程序(不适用于ipad),其中包含protrait和landscape两个方向。我的问题是有时候没有取向。如果我将设备转为横向模式,它只会停留在该模式,不会转到protrait模式,反之亦然。

enter image description here

我不知道这个问题。我在部署信息部分激活了所有设备方向模式。

任何人都可以告诉我这方面的解决方案。

提前致谢, 马赫什。

1 个答案:

答案 0 :(得分:0)

-(void)viewWillAppear:(BOOL)animated
{ 
  UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication]  statusBarOrientation];
  if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
    {
         // Write your orientation code here.
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        // Write your orientation code here.
    }
}
// For ios5 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
    if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
    {
         // Write orientation code here for ios5
    }
    else if (interfaceOrientation ==UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
         // Write orientation code here for ios5
    }


      return UIInterfaceOrientationMaskAll;

  }

 // Write code for ios6 and above
 -(BOOL)shouldAutorotate
 {

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
      return YES;
    }  
    else
       return  NO;
 }
 -(void)viewWillLayoutSubviews
 {
    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];

    if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
    {
          // Write orientation code here for ios5
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
         // Write orientation code here for ios5
    }


 }