当前 UIViewController 未完全显示

Posted

技术标签:

【中文标题】当前 UIViewController 未完全显示【英文标题】:Present UIViewController not showing completely 【发布时间】:2021-07-22 16:44:40 【问题描述】:

从 UITabBarViewController 呈现 UIViewController~>RootViewController.

let uploadViewController = UIStoryboard.identifier(.Home).instantiateViewController(identifier: "UploadViewController") as! UploadViewController
let navigationController = UINavigationController(rootViewController: uploadViewController)
navigationController.modalPresentationStyle = .overFullScreen
navigationController.statusBar(colour: .ThemeColor)
self.present(navigationController, animated: false, completion: nil)

//上传视图控制器

override func viewDidLoad() 
    super.viewDidLoad()
    self.addCrossAction()
    setTitle(text: "Upload")

    // Do any additional setup after loading the view.


func addCrossAction()
    navigationController?.navigationBar.backgroundColor = .ThemeColor
    navigationController?.isNavigationBarHidden = false
    navigationController?.navigationBar.hide_NavigationBar_BottonLine()
    let button = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
    button.setImage(UIImage(named: "crossButtonWhite"), for: .normal)
    button.addTarget(self, action: #selector(crossButtonClicked), for: .touchUpInside)
    navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button)

观察到 NavigationBar 未完成显示..

请在下面找到图片。

如何拥有完整的蓝色 .ThemeColor NavigationBar。

【问题讨论】:

更改状态栏背景颜色。 ***.com/a/60150062/14733292 发现有帮助的扩展 【参考方案1】:

代替:

navigationController?.navigationBar.backgroundColor = .ThemeColor

尝试:

UINavigationBar.appearance().barTintColor = .ThemeColor

或(ios >13):

UINavigationBarAppearance().backgroundColor = .ThemeColor

【讨论】:

【参考方案2】:

如果你想要带有大标题的全蓝条

navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always

否则,在您的表格视图顶部设置一个带有 ThemeColor 背景的虚拟视图,并将表格锚定到虚拟视图底部,然后再分配给您的导航栏背景颜色以清除。

声明你的 dummyView:

let dummyView = UIView()

在 viewDidLoad 中:

dummyView.backgroundColor = .ThemeColor
dummyView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(dummyView)
dummyView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
dummyView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
dummyView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
dummyView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true

之后将 tableView 顶部约束分配给 dummyView 底部约束... 如果您搜索扩展程序以编程方式设置导航栏,请查看我的https://***.com/a/58361273/5575955

【讨论】:

以上是关于当前 UIViewController 未完全显示的主要内容,如果未能解决你的问题,请参考以下文章

UIViewController 内容未显示在情节提要上

未显示子类 UIViewController

UITabBarController 未显示其内容的所有大小(UIViewController)

为啥情节提要 ui 元素未显示在 xcode 9 中的 UIViewController 上

UIScrollView 未显示在 UIViewController 上

iphone UIViewController 基子类未在 UINavigationController 中显示视图