2012-10-17 29 views
6

我在我的应用程序中使用主控制器和详细控制器的自定义分割视图控制器。支持不同视图控制器在iOS 6.0中的不同方向

- (id)initWithMasterController:(UIViewController*)aMasterController 
      detailedController:(UIViewController*)aDetailedController; 

提供给主控制器和细节上的控制器控制器的UINavigationController。

由于我的应用程序的一部分,有两种可能的情况下,进行定向处理:

  1. 当控制器六个组合在主和细节控制器的使用,所有的方向都支持的应用程序。
  2. 单独在细节控制器上有一个StudentDetailsViewController时,只能支持两种可能的方向。 (风景)

当过设备的方向发生改变,下面的事情发生版本的iOS以下6.0

  1. -shouldAutorotateToInterfaceOrientation:方法被调用。该方法的实现如下:在运行时,我将请求转发给主控制器,并使用相同的调用将详细控制器转发给控制器。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
        BOOL res = [masterController shouldAutorotateToInterfaceOrientation:interfaceOrientation] 
           && [detailedController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
        return res; 
    } 
    
  2. masterController的-shouldAutorotateToInterfaceOrientation将返回TRUE。下面是StudentViewController中该方法的实现。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
        return (IS_IPAD) ? UIInterfaceOrientationIsLandscape(interfaceOrientation) 
            : UIInterfaceOrientationIsPortrait(interfaceOrientation); 
    } 
    

以获得新的定向信息被改变的能力帮我决定是否转动应启用。

与iOS 6.0:

当过设备的方向发生改变,下面的东西的iOS 6.0

版本
  1. 拆分视图控制器的方法-shouldAutorotate发生被调用。它的实施是低于

    - (BOOL)shouldAutorotate { 
        BOOL res = [masterController shouldAutorotate] 
           && [detailedController shouldAutorotate]; 
        return res; 
    } 
    
  2. 的detailedController的shouldAutorotate调用navigationController。自动旋转功能的StudentsController实施:

    - (BOOL)shouldAutorotate { 
        return YES; 
    } 
    
    - (NSUInteger)supportedInterfaceOrientations { 
        return (UIInterfaceOrientationMaskLandscapeLeft 
          | UIInterfaceOrientationMaskLandscapeRight); 
    } 
    

但与iOS 6.0,我无法控制的方向。尽管supportedInterfaceOrientations方法被调用,但在detailsController的shouldAutorotate方法调用StudentsDetailsController的shouldAutorotate方法时,shouldAutorotateMethod不遵守supportedInterfaceOrientations方法中提到的选项。

UPDATE:

我阅读文档,并在document提供了下面的注解。

有时您可能希望动态禁用自动旋转。例如,对于 示例,如果要在短时间内完全禁止旋转 ,则可以执行此操作。您必须暂时禁用想要手动控制 状态栏位置的 方向更改(例如,当您调用 setStatusBarOrientation:animated:方法时)。

如果要暂时禁用自动旋转,请避免使用 操纵方向遮罩来执行此操作。请改为在最顶端的视图控制器上覆盖shouldAutorotate方法 。在执行任何自动旋转之前调用此方法为 。如果它返回NO,那么将禁止旋转 。

是否可以暂时禁用基于当前方向的自动旋转?

+0

的代码格式无法正确完成.. – Krishnan

+0

你有没有解决这个问题?我有同样的问题,无法弄清楚如何处理这两个ios5和6 – Stas

+0

没有我没有解决它.. – Krishnan

回答

0

我相信这是iOS中的一些问题,其中rootViewController没有参考childViewController的首选方向。但是,你应该尝试类似以下内容:

if (self.interfaceOrientation != UIInterfaceOrientationPortrait) 
{ 
    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait]; 
} 

改变方向回纵向对于给定的观点。

0

在您的应用程序中,委托类定义了以下方法,该方法在应用程序中的任何其他旋转方法之前被调用。

创建一个标志(isRotationEnabled),它将决定你的应用程序的方向。

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {  

return self.isRotationEnabled ? 
    UIInterfaceOrientationMaskAll : 
    UIInterfaceOrientationMaskPortrait; 
} 

变化根据你不同的条件下,这种标志的应用程序使用下面的代码

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
appDelegate.isRotationEnabled = NO; 
相关问题