为什么我的 UITabBar 按钮出现变形并且按钮字体发生变化?

Why do my UITabBar button appears distorted and button font changes?

我有一个 UITabBar 应用程序,它还涉及一个 UINavController,然后是一个 UITableView,所以:

UITabBarView -> UINavController -> UITableView -> UIController

当我进入 UIController 视图时,我隐藏了 tabar show 我可以最大化视图。当我回到我的 UITableView 时,标签栏向上显示 1 秒偏移,然后重新呈现到正确的位置,但字体不同。请参阅下面的照片以帮助理解问题:

Normal View of the TabBar shown below the UITableView

UIControlView with the TabBar hidden

Re-rendered TabBar under the UITableView

不幸的是,我无法抓取显示 UITabBar 区域外的 TabBar 图标的动画。

如有任何帮助,我们将不胜感激!

在@Mocha 的帮助下,我在 viewWillAppear 中为 UINavController 添加了 self.tabBarController.tabBar.hidden = false,然后在 viewWillDissappear 中将其设置为 "true"。

您可以通过在 viewWillAppear 方法中设置 tabBarController.tabBar.hidden = false/true 以编程方式执行此操作,而不是使用 xib

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    tabBarController?.tabBar.isHidden = true // or false
}

您可以使用故事板隐藏 UITabBar,当您返回 UITabBar 时会显示。

首先进入storyboard和select你想在视图显示时隐藏TabBar的视图,并启用Hide Boutton bar on push

并转换到要隐藏 TabBar 的视图,使用此代码:

 let SecondViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "yourview") as! yourview
 self.navigationController?.pushViewController(SecondViewController, animated: true)

我 运行 在 Xcode 10.1 和模拟器 12.1 下遇到了同样的问题:

  • 从隐藏的标签栏返回时出现奇怪的动画(使用 'Hides Bottom Bar on Push'); TabBar 项目在 TabBar 之外并偏移到 TabBar 的左侧和上方,然后到位

  • 之后 TabBarItems 的显示失真

对我来说,它看起来与模拟器渲染有关,因为它在设备上测试时工作正常。

如果其他人遇到此问题,我建议首先在真实设备上快速尝试测试(在投入大量时间之前)。