Adding UIViewController messes up screen orientation

╄→гoц情女王★ 提交于 2019-12-12 03:43:01

问题


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];

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.

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!


回答1:


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;
}


来源:https://stackoverflow.com/questions/16672227/adding-uiviewcontroller-messes-up-screen-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!