IOS 下获取 rootviewcontroller 的版本不同的问题解决办法
IOS下获取rootviewcontroller的版本不同的问题解决办法
一般原生的
[[UIApplicationsharedApplication].keyWindow.rootViewControllerpresentModalViewController:selfanimated:NO];
可以获取 系统的 rootviewcontroller
但cocos2d-x2.1.1在appcontroller.mm内定义的加载方法是
//SetRootViewControllertowindow
if([[UIDevicecurrentDevice].systemVersionfloatValue]<6.0)
{
//warning:addSubViewdoesn'tworkoniOS6
[windowaddSubview:viewController.view];
}
else
{
//usethismethodonios6
[windowsetRootViewController:viewController];
}
也就是说 只有在ios6下才设置rootview 其他时候是使用addsubview的方法加载。
所以相应的获取rootviewcontroller方法要改为。
if([[UIDevicecurrentDevice].systemVersionfloatValue]<6.0)
{
//warning:addSubViewdoesn'tworkoniOS6
NSArray*array=[[UIApplicationsharedApplication]windows];
UIWindow*win=[arrayobjectAtIndex:0];
UIView*ui=[[winsubviews]objectAtIndex:0];
UIViewController*ctrol=(UIViewController*)[uinextResponder];
}
else
{
//usethismethodonios6
UIViewController*ctrol=[UIApplicationsharedApplication].keyWindow.rootViewController];
}
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
热门推荐
10 小红书生日祝福语简短
11 哥哥新婚祝福语创意简短
12 舅舅大婚文案祝福语简短
13 中考祝福语简短高级句
14 生日祝福语外国诗词简短
15 村里伴娘祝福语大全简短
16 中秋祝福语给父亲简短
17 7月贺卡祝福语简短
18 良师益友祝福语简短