ios - 如何以编程方式创建带有动态选项卡的选项卡栏?底部黑屏问题
问题描述
我想用动态标签创建标签栏。我已经创建了带有动态选项卡的选项卡栏,但是当我从选项卡栏屏幕导航到详细信息屏幕时,该详细信息视图控制器中有黑色空间。请建议我实施它的正确方法。这是我的代码。
func creatTabBarProgrammatically(bottomMenuArray:[Any]) {
DispatchQueue.main.async {
self.navigationController?.setNavigationBarHidden(true, animated: false)
let tabBarController = UITabBarController()
tabBarController.tabBar.backgroundImage = self.getImageWithColor(UIColor.white, size: CGSize(width: self.view.frame.size.width, height: 49))
tabBarController.hidesBottomBarWhenPushed = true
let firstViewController = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
let ordersViewController = self.storyboard?.instantiateViewController(withIdentifier: "OrdersViewController") as! OrdersViewController
let myProfileViewController = self.storyboard?.instantiateViewController(withIdentifier: "MyProfileViewController") as! MyProfileViewController
var controllers = [Any]()
controllers.append(firstViewController)
for i in 0 ..< bottomMenuArray.count{
if let dict = bottomMenuArray[i] as? [String:Any]{
if let name = dict["name"] as? String{
if name == "orders"{
controllers.append(ordersViewController)
}
else if name == "profile"{
controllers.append(myProfileViewController)
}else{
}
}
}
}
tabBarController.viewControllers = controllers as? [UIViewController]
// Setting Title selected image and unselected image to tab
for i in 0 ..< bottomMenuArray.count{
if let dict = bottomMenuArray[i] as? [String:Any]{
if let name = dict["name"] as? String{
if name == "orders"{
let tabBarItem :UITabBarItem = tabBarController.tabBar.items![i + 1]
tabBarItem.title = "Orders"
tabBarItem.selectedImage = UIImage(named: "tabordersselected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
tabBarItem.image = UIImage(named: "tabordersunselected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
}
else if name == "profile"{
let tabBarItem :UITabBarItem = tabBarController.tabBar.items![i + 1]
tabBarItem.title = "Profile"
tabBarItem.selectedImage = UIImage(named: "tabprofileselected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
tabBarItem.image = UIImage(named: "tabprofileunselected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
}else{
}
}
}
}
let tabBarItem1:UITabBarItem = tabBarController.tabBar.items![0]
tabBarItem1.title = "Home"
tabBarItem1.selectedImage = UIImage(named: "tabhomeselected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
tabBarItem1.image = UIImage(named: "tabhomeunseleted")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0 as! UIViewController)}
self.navigationController!.pushViewController(tabBarController, animated: false)
}
}
解决方案
尝试在控制器上强制布局你得到底部黑条
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.navigationController?.view.setNeedsLayout()
}
推荐阅读
- java - HttpServletRequest getParameterMap - 单独获取表单参数
- c++ - 弗兰克·卢纳 (Frank Luna) 对他的书“使用 DirectX12 进行 3D 游戏编程”的介绍中的盒子示例的问题
- python - 如何通过css选择器查找包含属性和文本的元素
- python - 使用 Azure CLI、Rest API 或 Python 在 Azure ADLS gen2 中复制文件
- python - 具有超过 3 列的 ColumnTransformer
- overlap - 如何控制kmz中多边形的重叠顺序
- azure - 如何在发布管道中将文件保存到 Azure 存储帐户?
- python - INFO:tensorflow:Error 报告给 Coordinator:
,发现 2 个根错误 - javascript - 填充输入字段时启用 p:commandLink
- java - 如何为由 div 和 class 创建的结帐创建 xpath