Pregunta

A really simple question that didn't pop up on me during the search here and on Google. How do you restrict a certain UIView on UIViewController to not rotate when all other views do?

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

The code above just doesn't seem to work.

I'm using iOS 6.

¿Fue útil?

Solución

iOS 6 has different way of handling rotation. You have to use shouldAutorotate method on the topmost view controller. Below is the quote from Apple

If you want to temporarily disable automatic rotation, avoid manipulating the orientation masks to do this. Instead, override the shouldAutorotate method on the topmost view controller. This method is called before performing any autorotation. If it returns NO, then the rotation is suppressed.

You can try something like

- (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;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top