gpt4 book ai didi

ios - UITabBarViewController 的自定义 TabBar 布局

转载 作者:搜寻专家 更新时间:2023-11-01 07:05:32 27 4
gpt4 key购买 nike

请引用这个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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com