IOS 下獲取 rootviewcontroller 的版本不同的問(wèn)題解決辦法
IOS 下獲取 rootviewcontroller 的版本不同的問(wèn)題解決辦法
一般 原生的
[[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]; }
也就是說(shuō) 只有在 ios6 下 才設(shè)置rootview 其他時(shí)候是 使用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]; }
如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
淺述iOS11 Xcode 9 按住command 單擊 恢復(fù)到從前(直接跳轉(zhuǎn)到定義)
這篇文章主要介紹了 iOS11 Xcode 9 按住command 單擊 恢復(fù)到從前(直接跳轉(zhuǎn)到定義)的相關(guān)資料,需要的朋友可以參考下2017-10-10iOS基于UIScrollView實(shí)現(xiàn)滑動(dòng)引導(dǎo)頁(yè)
這篇文章主要為大家詳細(xì)介紹了iOS基于UIScrollView實(shí)現(xiàn)滑動(dòng)引導(dǎo)頁(yè)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01iOS 本地存儲(chǔ)NSUserDefaults封裝代碼
下面小編就為大家分享一篇iOS 本地存儲(chǔ)NSUserDefaults封裝代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01iOS利用UIBezierPath + CAAnimation實(shí)現(xiàn)路徑動(dòng)畫(huà)效果
在iOS開(kāi)發(fā)中,制作動(dòng)畫(huà)效果是最讓開(kāi)發(fā)者享受的環(huán)節(jié)之一,這篇文章主要給大家介紹了關(guān)于iOS利用UIBezierPath + CAAnimation實(shí)現(xiàn)路徑動(dòng)畫(huà)效果的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10iOS實(shí)現(xiàn)不規(guī)則Button點(diǎn)擊效果實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于iOS實(shí)現(xiàn)不規(guī)則Button點(diǎn)擊的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位iOS開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04iOS AVCaptureSession實(shí)現(xiàn)視頻錄制功能
這篇文章主要為大家詳細(xì)介紹了iOS AVCaptureSession實(shí)現(xiàn)視頻錄制功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05