ios - UITabBarViewController 的自定义 TabBar 布局

标签 ios swift uitabbarcontroller uitabbar

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

相关文章:

iphone - 在 ScrollView 效果中显示带有动画的图像

ios - siwfty json 解析失败

ios - Swift - 为什么我的函数内的函数没有被调用?

ios - ObjC 如何在选择 TabBarItem 时弹出回 RootViewController

iOS - 设置 UITabBar 图标

ios - 如何将 Firebase 中的 child 的名字设置为来自文本字段的用户输入?

javascript - 是否可以通过网络浏览器 api 访问移动设备的电池状态或充电?

iphone - 从 id 获取 ViewController 名称并调用特定的 View 方法

ios - 处理 UITableView 绑定(bind)中的连接错误(Moya、RxSwift、RxCocoa)

ios - UITapGestureRecognizer 在第一个选项卡中不起作用