接手公司的項目,前段時間用iOS 11系統的手機運行程序,發現了一個bug,在程序首頁界面跳轉,但導航欄不跟着跳轉.經排查原因,問題出在了這塊代碼上,記錄一下.
GHTabBarController * tabBarController = [[GHTabBarController alloc] init];
HDMainNavigationController * tabBarNav = [[HDMainNavigationController alloc] initWithRootViewController:tabBarController];
tabBarNav.navigationBarHidden = YES;
[currentViewController presentViewController:tabBarNav animated:YES completion:^{
AppDelegate * appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegate.window.rootViewController = tabBarNav;
}];
看代碼,猜想前同事可能想既保留跳轉動畫,跳轉完之後,再把跳轉到的界面設置爲根視圖,但這種寫法在iOS 11系統上就出錯了.解決方式兩種:1.跳轉後不要再進行設置根視圖操作,2.或者直接設置爲根視圖,不走跳轉操作.