ios - 为什么 UITabbarController 太低了
问题描述
我已经实现了顶部项目的视图,UICollectionview
并UIPagecontroller
获得了类似页面标签的 android。
每个菜单都有一个容器ViewController
,但其中一个需要UITabBarController
.
为什么UITabBarController
会下降。
我曾尝试将 menuVIew(联系人、最近等)向上移动,但仍然无法正常工作。
解决方案
let tabBar = UITabBar()
override func viewDidLoad() {
super.viewDidLoad()
addTabbar()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
addHeightConstraintToTabbar()
}
func addTabbar() -> Void {
self.view.addSubview(tabBar)
tabBar.translatesAutoresizingMaskIntoConstraints = false
tabBar.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
tabBar.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
tabBar.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
let item1 = UITabBarItem(tabBarSystemItem: UITabBarSystemItem.bookmarks, tag: 1)
let item2 = UITabBarItem(tabBarSystemItem: UITabBarSystemItem.contacts, tag: 2)
tabBar.items = [item1, item2]
self.view.bringSubview(toFront: tabBar)
}
func addHeightConstraintToTabbar() -> Void {
let heightConstant:CGFloat = self.view.safeAreaInsets.bottom + 49.0
tabBar.heightAnchor.constraint(equalToConstant: heightConstant).isActive = true
}
推荐阅读
- sql-server - 在哪里可以找到创建的 localdb?
- assembly - 将汇编寄存器视为无符号与有符号
- python - Python:减少缺少值的小整数的内存使用
- reporting-services - 使用 SSRS 2019 进行自定义身份验证
- webpack - 输出多个 var
- mdriven - 如何控制注销行为?
- c# - 无法转换类型 IAsyncOperation
到蓝牙设备 - laravel - Laravel + Nuxt + Nginx:WebSocket 在连接建立之前关闭
- google-chrome - 如何确定 Chrome 显示警报对话框的原因?
- javascript - 如何使用 ngTemplateOutlet 以角度显示基于 roomList 数据的模板