请引用这个Answer .
我正在尝试做同样的事情,但是我想在标签栏应用程序中执行此操作,其中正在播放栏在应用程序的所有场景中都位于标签栏上方。
更新:
我想在屏幕底部(选项卡栏上方)和不同选项卡的内容 View 下方(而不是在它们上方)有一个 View 。此外,我希望能够在某个点删除此 View ,使主视图占据整个屏幕。
我可以使用提到的 Answer 来做到这一点通过以编程方式更改 nowPlaying
View 的约束。
最佳答案
使用 UITabBarViewController 子类可以:
例如:
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)
}
}
关于ios - UITabBarViewController 的自定义 TabBar 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48291081/