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];
}
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!