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 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短