在iOS 6中获取当前界面方向

Nou*_*Kmc 7 xcode objective-c ios

我在iOS 5.x中动态进行方向检查,如下所示:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==         UIInterfaceOrientationPortraitUpsideDown) 
 {
self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
// some more settings
}
else
{
self.profileNew.frame = CGRectMake(374, 540, 295, 58);
 // some more settings
}
 return YES;
}
Run Code Online (Sandbox Code Playgroud)

对于iOS 6,我做了以下代码,但那不起作用:

-(BOOL)shouldAutorotate{    
   return YES;
}

-(NSInteger)supportedInterfaceOrientations
{
 if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) 
  {
   self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
   // some more settings
  }
  else
  {
   self.profileNew.frame = CGRectMake(374, 540, 295, 58);
   // some more settings
  }
 return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

我如何像在iOS 5.x中那样检查iOS 6中的界面内容?

谢谢

Lev*_*evi 9

您可以使用该viewWillLayoutSubviews方法检查方向

[[UIApplication sharedApplication] statusBarOrientation];

并相应地设置你的帧.

希望这可以帮助!