Adding UIViewController messes up screen orientati

2019-09-12 16:11发布

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条回答
SAY GOODBYE
2楼-- · 2019-09-12 16:50

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;
}
查看更多
登录 后发表回答