1. 程式人生 > >iOS12.1 出現 tabbar 按鈕錯亂問題

iOS12.1 出現 tabbar 按鈕錯亂問題

更新12.1之後,發現push一個介面,返回的時候,tabBar上的圖示和文字出現從上往下移動的位置錯亂問題,瞬間內心不愉快了!

經過測試發現,如果使用系統OS12.1 UINavigationController + UITabBarController( UITabBar 磨砂),在popViewControllerAnimated 會遇到tabbar佈局錯亂的問題

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
   
   if (self.childViewControllers.count > 0) {
       
       //就是這行程式碼惹的禍
       viewController.hidesBottomBarWhenPushed = YES;
   }
   
   [super pushViewController:viewController animated:animated];
}

當你push進去隱藏了tabbar返回的時候就會重新設定他的frame。這個問題是 iOS 12.1 Beta 2 引入的問題,只要 UITabBar 是磨砂的,並且 push viewController 時 hidesBottomBarWhenPushed = YES 則手勢返回的時候就會觸發,出現這個現象的直接原因是 tabBar 內的按鈕 UITabBarButton 被設定了錯誤的 frame,frame.size 變為 (0, 0) 導致的。

解決辦法  

加上    [UITabBar appearance].translucent = NO;   完美解決