限制某些UIView在界面旋转时更改框架

时间:2013-09-17 11:24:22

标签: cocoa-touch ios6 uiview uikit auto-rotation

这是一个非常简单的问题,在搜索过程中和谷歌上没有出现在我身上。如果所有其他观看的内容,如何限制UIView上的某个UIViewController不旋转?

containerView.autoresizingMask = UIViewAutoresizingNone;
containerView.autoresizesSubviews = NO;

上面的代码似乎不起作用。

我正在使用iOS 6.

1 个答案:

答案 0 :(得分:1)

iOS 6有不同的处理旋转方式。您必须在最顶层的视图控制器上使用shouldAutorotate方法。以下是Apple的报价

  

如果要暂时禁用自动旋转,请避免操作方向遮罩来执行此操作。而是覆盖最顶层视图控制器上的shouldAutorotate方法。在执行任何自动旋转之前调用此方法。如果它返回NO,则旋转被抑制。

您可以尝试类似

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

      NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;
      if(self.window.rootViewController){
      // CHECK FOR A PARTICULAR VIEW CONTROLLER

         UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
         orientations = [presentedViewController supportedInterfaceOrientations];
      }
   return orientations;
}