一般 原生的
[[UIApplication sharedApplication].keyWindow.rootViewController presentModalViewController:self animated:NO];
可以 获取 系统的 rootviewcontroller
但 cocos2d-x 2.1.1 在 appcontroller.mm 内定义的 加载方法是
// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[window addSubview: viewController.view];
}
else
{
// use this method on ios6
[window setRootViewController:viewController];
}
也就是说 只有在 ios6 下 才设置rootview 其他时候是 使用addsubview的方法 加载。
所以 相应的 获取 rootviewcontroller方法 要改为。
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
NSArray* array=[[UIApplication sharedApplication]windows];
UIWindow* win=[array objectAtIndex:0];
UIView* ui=[[win subviews] objectAtIndex:0];
UIViewController* ctrol=(UIViewController*)[ui nextResponder];
}
else
{
// use this method on ios6
UIViewController* ctrol=[UIApplication sharedApplication].keyWindow.rootViewController];
}
本文详细介绍了在Cocos2d-x2.1.1中,针对iOS6系统,如何调整获取rootViewController的方法,以解决在不同iOS版本下加载视图控制器的问题。
145

被折叠的 条评论
为什么被折叠?



