我试过的解决方案:
>具有最大容器视图的ViewController中的UITabBarController,以及底部布局指南上方Container View49pt顶部的自定义视图:
问题:嵌入在底部的UITabBarController中的ViewControllers中的任何内容都不会显示,因为它们隐藏在自定义布局后面.我已经尝试在UITabBarController中覆盖大小forChildContentContainer,尝试更新底部布局指南,Nothing.我需要调整UITabBarController的容器视图的框架.
>再次尝试#1,但尝试在increasing the size of UITabBar之前解决隐藏在其后面的内容问题,然后使用ImageInset on every TabBarItem将其关闭,并在UITabBar上添加我的自定义视图.工作得不好.有时候我想隐藏自定义视图.
> UITabBarController作为root用户,每个子节点都是ViewController,带有Container View我的自定义视图:
但现在我有多个自定义视图实例浮动.如果我想更改其上的标签,则必须将其更改为所有视图.或隐藏等
>覆盖UITabBarController的UITabBar属性并返回我的自定义UITabBar(用xib充气),它具有UITabBar我的自定义视图.问题:可能是所有人最令人沮丧的尝试.如果使用类MyCustomTabBar:UITabBar {}的实例覆盖该属性,则不会显示任何选项卡!是的,我将myCustomTabBar的委托设置为self.
倾向于#3,但寻找更好的解决方案.
解决方法
本质上,我增加了原始UITabBar的大小以容纳自定义视图(并缩小上面的viewcontrollers的框架),然后在其上添加一个重复的UITabBar自定义视图.
这是我必须要做的事情.我上传了一个功能实例,可以是found in this repo:
class TabBarViewController: UITabBarController { var currentlyPlaying: CurrentlyPlayingView! static let maxHeight = 100 static let minHeight = 49 static var tabbarHeight = maxHeight override func viewDidLoad() { super.viewDidLoad() currentlyPlaying = CurrentlyPlayingView(copyFrom: tabBar) currentlyPlaying.tabBar.delegate = self view.addSubview(currentlyPlaying) tabBar.isHidden = true } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) currentlyPlaying.tabBar.items = tabBar.items currentlyPlaying.tabBar.selectedItem = tabBar.selectedItem } func hideCurrentlyPlaying() { TabBarViewController.tabbarHeight = TabBarViewController.minHeight UIView.animate(withDuration: 0.5,animations: { self.currentlyPlaying.hideCustomView() self.updateSelectedViewControllerLayout() }) } func updateSelectedViewControllerLayout() { tabBar.sizeToFit() tabBar.sizeToFit() currentlyPlaying.sizeToFit() view.setNeedsLayout() view.layoutIfNeeded() viewControllers?[self.selectedIndex].view.setNeedsLayout() viewControllers?[self.selectedIndex].view.layoutIfNeeded() } } extension UITabBar { open override func sizeThatFits(_ size: CGSize) -> CGSize { var sizeThatFits = super.sizeThatFits(size) sizeThatFits.height = CGFloat(TabBarViewController.tabbarHeight) return sizeThatFits } }