I have an app that is designed to run Landscape. It is a Cocos2D app. It works fine until I add another window (such as for displaying ads) or if I display a modal view controller.
When I do that, the window/view still rotates even though I have explicity set shouldAutoRotate = NO
Furthermore, Apple says that supportedInterfaceOrientations will not be called if shouldAutorotate returns NO. However, it is called both before and after shouldAutorotate is called. Why is this happening and what is the solution for managing auto rotation in iOS 8?
While I have seen many SO problems addressing auto rotation issues in previous iOS versions (with the most thorough description of how to set up to manage autorotation found in shouldAutorotateToInterfaceOrientation not being called in iOS 6), none seem to address the problem of supportedInterfaceOrientations being called even though shouldAutoRotate = NO; and the view still rotating even though it is being told not to rotate.
To be completely thorough with my explanation, here is a description of how I have set this up:
First, to get the Launch Images to display, I was forced to set the device orientation in the info.plist to support all orientations. Otherwise, the screen is black on launch.
Next, here is how my code is implemented:
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
...
// Init the 2nd window
secondWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // secondWindow is defined as a UIWindow
// Init the second View Controller
nrViewController = [[NonRotatingViewController alloc] initWithNibName:nil bundle:nil]; // nrViewController is defined as a UIViewController
nrViewController.wantsFullScreenLayout = YES; // this insures that if the status bar it transparent, the view underlaps it
[secondWindow setRootViewController:nrViewController]; // The root view controller provides the content view of the window.
[secondWindow addSubview: nrViewController.view]; // Adds a view to the end of the receiver’s list of subviews
[secondWindow makeKeyAndVisible]; // make the receiver the main window and displays it in front of other windows
EAGLView *glView = [EAGLView viewWithFrame:[secondWindow bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
// attach the openglView to the director
CCDirector *director = [CCDirector sharedDirector];
[director setOpenGLView:glView];
[director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
// make the OpenGLView a child of the view controller
[nrViewController setView:glView]; // bug fix requires a non-rotating view controller and window on top of a rotating one.
}
The NonRotatingViewController in the second window returns NO when shouldAutorotate is called. Also 0 is returned when supportedInterfaceOrientations is called (although technically it shouldn't matter what I return because Apple says it shouldn't be called).
For the modal view controller and the ad view controller, I have tried both shouldAutorotate = NO and YES. Neither approach will keep the second window/nrViewController from rotating. I have spent days trying all sorts of combinations, but none of them works. Do you see what I might be doing wrong?
So to reiterate my question, why is supportedInterfaceOrientations being called and why is the view still rotating even though shouldAutoRotate = NO?