UIDeviceOrientationDidChangeNotification为UIOrientationLandscapeRight返回UIOrientationLandscapeLeft

时间:2012-10-15 05:53:13

标签: iphone notifications orientation ios6

我正在为UIDeviceOrientationDidChangeNotification注册我的viewcontroller,它返回错误的设备方向。 我在viewcontroller的init函数中注册它

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(handleOrientationChangeNotification:) name: UIDeviceOrientationDidChangeNotification object: nil];

这是我的设备通知接收方法。

-(void)handleOrientationChangeNotification:(NSNotification *)notification
{ 
    if(IS_IPHONE)
    {
        UIDeviceOrientation currentDeviceOrientation =  [[UIDevice currentDevice] orientation];
    .
    .
    .
}

每当设备方向改变时,我总是出错方向。

2 个答案:

答案 0 :(得分:3)

我在此link

上找到了苹果网站上的解决方案

UIDeviceOrientationLandscapeRight已分配给UIInterfaceOrientationLandscapeLeftUIDeviceOrientationLandscapeLeft已分配给UIInterfaceOrientationLandscapeRight。原因是旋转设备需要沿相反方向旋转内容。

答案 1 :(得分:2)

这可能正在发生,因为Apple改变了管理UIViewController方向的方式。 在Ios6中Oreintation处理不同,在iOS6 shouldAutorotateToInterfaceOrientation方法中已弃用.iOS容器(例如UINavigationController)不咨询他们的孩子以确定他们是否应该自动旋转。默认情况下,应用程序和视图控制器支持的界面方向对于iPad惯用语设置为UIInterfaceOrientationMaskAll,对于iPhone惯用语设置为UIInterfaceOrientationMaskAllButUpsideDown

For More Information regarding the same You should visit this link 下面我已经为处理方向改变做了类别。

所以你必须实现另外两种方法来管理iOS6中UIViewController的方向。

在IOS6中引入允许方向更改

 - (BOOL)shouldAutorotate
  {

    return YES;

  }

返回设备

支持的Oreintation数量
 - (NSUInteger)supportedInterfaceOrientations
 {
    return  UIInterfaceOrientationMaskAll;

 }

现在检查你得到的方向。

编辑:将此代码放置到以View ViewController添加的FirstViewController中。这将帮助UIViewController确定它的Orientation。

@implementation UINavigationController (RotationIn_IOS6)

 -(BOOL)shouldAutorotate
  {
   return [[self.viewControllers lastObject] shouldAutorotate];
  }

  -(NSUInteger)supportedInterfaceOrientations
 {
   return [[self.viewControllers lastObject] supportedInterfaceOrientations];
 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
 {
   return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
 }

 @end

我希望我会对你有所帮助。