Similar to what the Spotify or Apple Music app does when a song is playing, it places a custom view on top of the UITabBar:
![enter image description here](https://i.stack.imgur.com/zN664.png)
我尝试过的解决方案:
-
UITabBarController in a ViewController with a max-sized Container View, and the custom view on top of the Container View49pt above the Bottom Layout Guide:
Problem: Any content in ViewControllers embedded in the UITabBarController constrained to the bottom don't show because they're hidden behind the custom layout. I've tried overriding size forChildContentContainer
in UITabBarController, tried updating the bottom layout guide, Nothing. I need to resize the frame of container view of the UITabBarController.
-
再次尝试#1,但尝试解决隐藏在其后面的内容的问题增加 UITabBar 的大小 https://stackoverflow.com/questions/24397189/changing-the-height-of-uitabbar-in-ios7-8,然后使用每个 TabBarItem 上的 ImageInset https://stackoverflow.com/questions/37457711/resize-all-viewcontroller-frames-in-tabbarcontroller将其关闭,并在 UITabBar 顶部添加我的自定义视图。效果不太好。有时我想隐藏我的自定义视图。
-
UITabBarController as root, with each children being a ViewController with a Container View + my custom view:
But now I have multiple instances of my custom view floating around. If I want to change a label on it, have to change it to all views. Or hide, etc.
-
覆盖 UITabBarController 的 UITabBar 属性并返回具有 UITabBar + 我的自定义视图的自定义 UITabBar(用 xib 对其进行膨胀)。Problem:可能是所有尝试中最令人沮丧的。如果您使用以下实例覆盖该属性class MyCustomTabBar : UITabBar {}
,没有标签显示!是的,我设置了代表myCustomTabBar
to self
.
倾向于#3,但正在寻找更好的解决方案。
如果您继承 UITabBarController 并以编程方式添加视图,这实际上非常容易。使用此技术会自动支持选项卡栏的旋转和大小更改,无论您使用的是哪个版本。
class CustomTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
//...do some of your custom setup work
// add a container view above the tabBar
let containerView = UIView()
containerView.backgroundColor = .red
view.addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
containerView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
// anchor your view right above the tabBar
containerView.bottomAnchor.constraint(equalTo: tabBar.topAnchor).isActive = true
containerView.heightAnchor.constraint(equalToConstant: 50).isActive = true
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)