添加UIViewController会使屏幕方向混乱 [英] Adding UIViewController messes up screen orientation
问题描述
我从一个GLSprite
示例应用开始(源代码),然后通过添加
I started with a GLSprite
sample app (source code), then added a UIViewController
by adding
UIViewController *vc = [[UIViewController alloc] init];
vc.view = glView;
self.window.rootViewController = vc;
[window makeKeyAndVisible];
到GLSpriteAppDelegate::applicationDidFinishLaunching.
的末尾控制器似乎正在工作,因为现在我可以弹出游戏中心窗口,但是它弄乱了我的屏幕orientation
.该应用程序在portrait
中效果很好,但在所有其他rotations
中,它的侧面错误地带有白色条,就像其中一个视图旋转了90度一样.
to the end of GLSpriteAppDelegate::applicationDidFinishLaunching.
The controller seems to be working as now I can pop up gamecenter windows, but it has messed up my screen orientation
. The app is fine in portrait
, but in all other rotations
it incorrectly has white bars on the side, like one of the views is rotated 90 degrees.
我在EAGLView::initWithCoder
中执行[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
,然后尝试将其移到applicationDidFinishLaunching
的末尾,但是它具有相同的行为.
I was doing [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
in EAGLView::initWithCoder
, I then tried moving it to the end of applicationDidFinishLaunching
but it had the same behavior.
任何人都可以帮忙吗?我该怎么做才能解决或调试此问题?谢谢!
Can anyone help? What can I do to fix or debug this? Thank you!
推荐答案
问题是新的UIViewController正在旋转,而我的游戏需要始终显示纵向屏幕.要修复,我创建了一个自定义的viewcontroller并实现了
The issue was the new UIViewController was rotating, when my game expects an always portrait screen. To fix I created a custom viewcontroller and implemented
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return 0;
}
这篇关于添加UIViewController会使屏幕方向混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!