溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

IOS 下獲取 rootviewcontroller 的版本不同的問題解決辦法

發(fā)布時間:2020-09-23 09:15:25 來源:腳本之家 閱讀:390 作者:無奈的朱熹 欄目:移動開發(fā)

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ū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

向AI問一下細節(jié)

免責(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)容。

AI