在iOS 8中,即使shouldAutoRotate = NO,也会调用supportedInterfaceOrientations;视图仍在旋转

时间:2014-10-03 17:54:47

标签: cocos2d-iphone ios8 uiinterfaceorientation autorotate

我有一个旨在运行Landscape的应用。这是一个 Cocos2D 应用。它工作正常,直到我添加另一个窗口(如显示广告)或我显示模态视图控制器。

当我这样做时,即使我明确设置shouldAutoRotate = NO

,窗口/视图仍会旋转

此外,Apple表示如果shouldAutorotate返回NO,则不会调用 supportedInterfaceOrientations 。但是,在调用shouldAutorotate之前和之后都会调用它。为什么会发生这种情况?在iOS 8中管理自动轮换的解决方案是什么?

虽然我已经看到许多SO问题解决了以前iOS版本中的自动旋转问题(有关如何设置管理shouldAutorotateToInterfaceOrientation not being called in iOS 6中发现的自动旋转的最全面的描述),但似乎没有一个解决supportInterfaceOrientations的问题。虽然shouldAutoRotate = NO,但仍然调用;即使被告知不要旋转,视图仍然会旋转。

为了完全彻底解释我的解释,下面是对我如何设置的说明:

首先,为了显示启动图像,我被迫在info.plist中设置设备方向以支持所有方向。否则,启动时屏幕会变黑。

接下来,我的代码实现方式如下:

- (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.
}

第二个窗口中的NonRotatingViewController在调用shouldAutorotate时返回NO。调用supportedInterfaceOrientations时也会返回0(虽然从技术上来说它不应该重要,因为Apple说它不应该被调用)。

对于模态视图控制器和广告视图控制器,我已尝试过shouldAutorotate = NO和YES。这两种方法都不会阻止第二个窗口/ nrViewController旋转。我花了好几天尝试各种组合,但没有一个能起作用。你看到我可能做错了吗?

所以重申一下我的问题,为什么调用supportedInterfaceOrientations,为什么视图仍在旋转,即使shouldAutoRotate = NO?

0 个答案:

没有答案