您好,登錄后才能下訂單哦!
IOS 下獲取 rootviewcontroller 的版本不同的問題解決辦法
一般 原生的
[[UIApplication sharedApplication].keyWindow.rootViewController presentModalViewController:self animated:NO];
可以 獲取 系統(tǒng)的 rootviewcontroller
但 cocos2d-x 2.1.1 在 appcontroller.mm 內(nèi)定義的 加載方法是
// 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 下 才設(shè)置rootview 其他時候是 使用addsubview的方法 加載。
所以 相應(yīng)的 獲取 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]; }
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。