iOS转屏偶尔只在第一次转屏时失败

u011079487 2017-06-02 11:58:52
游戏中,启动后的场景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;
...全文
332 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
不懂IOS,我也没办法帮你解决啊
u011079487 2017-06-02
  • 打赏
  • 举报
回复
其实我怀疑是首个viewController 初始化的时候出问题,但是去检查时似乎又没发现出错(估计是我技术不好) 补充初始化代码: cocos2d::Application *app = cocos2d::Application::getInstance(); app->initGLContextAttrs(); cocos2d::GLViewImpl::convertAttrs(); sharedInstance = self; _viewDelegate = [[AppController alloc] init]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat depthFormat: cocos2d::GLViewImpl::_depthFormat preserveBackbuffer: NO sharegroup: nil multiSampling: NO numberOfSamples: 0 ]; [eaglView setMultipleTouchEnabled:YES]; self.viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; self.viewController.wantsFullScreenLayout = YES; self.viewController.view = eaglView; [window setRootViewController:_viewController]; [window makeKeyAndVisible]; [[UIApplication sharedApplication] setStatusBarHidden: YES]; [[UIApplication sharedApplication] setIdleTimerDisabled: YES]; cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); cocos2d::Director::getInstance()->setOpenGLView(glview);

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧