UITabBarViewController的自定义TabBar布局 [英] Custom TabBar layout for UITabBarViewController
问题描述
请参阅此答案.
我正在尝试做同样的事情,但是我想在Tab Bar应用程序中执行此操作,在该应用程序的所有场景中,正在播放"栏都位于Tab Bar上方.
I am trying to do the same thing, however I want to do this in a Tab Bar App where the Now Playing bar is above the Tab Bar in all the scenes of the app.
更新:
我想在屏幕底部(标签栏上方)和不同标签的内容视图下方(而不是它们上方)有一个视图.另外,我希望能够在某个时候删除此视图,以使主视图占据整个屏幕.
I want to have a view at the bottom of the screen (above the tab bar) and under the content views of the different tabs (not above them). In addition, I want to have the ability to remove this view at a certain point making the main view take the whole screen.
我可以使用提及的答案,通过以编程方式更改nowPlaying
视图的约束来实现此目的.
I can do this using the mentioned Answer by changing the constraints of the nowPlaying
view programmatically.
推荐答案
使用UITabBarViewController子类是可能的:
Using UITabBarViewController subclass it is possible:
例如:
class DashBoardViewController: UITabBarController {
let nowPlayingBar:UIView = {
let view = UIView(frame: .zero)
view.backgroundColor = .blue
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
initView()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
nowPlayingBar.frame = tabBar.frame
}
override func viewDidAppear(_ animated: Bool) {
var newSafeArea = UIEdgeInsets()
// Adjust the safe area to accommodate
// the height of the bottom views.
newSafeArea.bottom += nowPlayingBar.bounds.size.height
// Adjust the safe area insets of the
// embedded child view controller.
self.childViewControllers.forEach({$0.additionalSafeAreaInsets = newSafeArea})
}
private func initView() {
nowPlayingBar.frame = tabBar.frame
view.addSubview(nowPlayingBar)
}
}
这篇关于UITabBarViewController的自定义TabBar布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!