iOS转屏偶尔只在第一次转屏时失败
游戏中,启动后的场景A是竖屏的,从场景A进入场景B时,游戏强制转为横屏,如果从场景B返回场景A,又要转回竖屏。
现在出现一个BUG,偶尔会在启动程序后第一次从场景A进入场景B时,转屏失败,但是返回场景A就不会有问题,而且马上再一次进入场景B都会正常转换了。
转换横竖屏的时候,正常转换的话,导航栏也会跟着转换,转换失败时,导航栏是没有变,但是输出屏幕方向信息确是和转换成功时一样的( [UIApplication sharedApplication].statusBarOrientation)
重点:
1、BUG只在启动后的第一次转横屏时候出现,转回竖屏或者第一次以后是一定不会出现的
2、BUG不是必定出现的。
3、不管成功还是失败都进入了转屏函数,并且在函数中打印各种width、height、statusBarOrientation等等都是一样的
if (self.landSceneController != nil) {
return ;
}
NSLog(@"======= 转成横屏 =======");
//打印设备方向状态
NSLog(@"interface = %zi", [UIApplication sharedApplication].statusBarOrientation);
id eaglView = self.viewController.view ;
self.viewController.view = nil;
if (self.landSceneController == nil) {
self.landSceneController = [[LandSceneController alloc] initWithNibName:nil bundle:nil];
self.landSceneController.wantsFullScreenLayout = YES;
}
self.landSceneController.view = eaglView;
[window setRootViewController:self.landSceneController];
[self.viewController presentViewController:self.landSceneController animated:NO completion:nil];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
CGRect screenBounds = [UIScreen mainScreen].bounds;
if(screenBounds.size.height > screenBounds.size.width)
{
int temp = screenBounds.size.height;
screenBounds.size.height = screenBounds.size.width;
screenBounds.size.width = temp;
}
cocos2d::GLView *glview = cocos2d::Director::getInstance()->getOpenGLView();
if (glview)
{
CCEAGLView *eaglview = (CCEAGLView*) glview->getEAGLView();
[eaglview setBounds:CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height)];
if (eaglview)
{
CGSize s = CGSizeMake([eaglview getWidth], [eaglview getHeight]);
cocos2d::Application::getInstance()->applicationScreenSizeChanged(int(s.width), int(s.height));
}
}
//打印设备方向状态
NSLog(@"interface = %zi", [UIApplication sharedApplication].statusBarOrientation);
[self.viewController release];
self.viewController = nil;