3

I have a GLKViewController with two views: a GLKView and a transparent UIView showing some commands.

The GLKViewController supports two device orientations: portrait and landscape-right.

When the device is rotated from portrait to landscape I would like to:

  • NOT rotate the GLKView;
  • rotate the overlaid UIView with the commands.

Basically the GLKView should stay always in portrait, while the other view should follow the device orientation.

The GLKViewController is in a NavigationController. Either I need to have the NavigationController rotating in landscape or I need to implement a fake Navigation Bar and perform the 'pop' programmatically.

I saw a solution which simply rotated the view (after catching a notification), but I would like to keep the animation rotating that view.

I tried to use another UIViewController subclass, receiving the GLKViewController and the View with the commands as two child UIViewControllers but it did not work: the screen stayed black.

Ed Liss
  • 546
  • 4
  • 16
Antonio Sesto
  • 2,868
  • 5
  • 33
  • 51

1 Answers1

-1

When a UINavigationController is involved, create a category on the UINavigationController and override supportedInterfaceOrientations.

 #import "UINavigationController+Orientation.h"

 @implementation UINavigationController (Orientation)

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

-(BOOL)shouldAutorotate
{
return YES;
}

@end  

Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate.

How to create a category

  1. Add a new file (Objective c- category under cocoa touch)

  2. Category : Orientation on UINavigationController

  3. Add the above code to UINavigationController+Orientation.m

Harsh
  • 2,852
  • 1
  • 13
  • 27
  • Either I did not understand your answer or you did not understand my question. I am not asking how different controllers in the same navigation unit can respond differently to device orientation changes. My question concerns how to have two views in the same controller to respond differently to device orientation changes. – Antonio Sesto Feb 27 '14 at 19:11
  • This isn't an answer to the question. It doesn't address how to have some UIViews remain unrotated when their enclosing UIViewController rotates. – Benjohn Sep 29 '14 at 09:12