首页 > 解决方案 > 全屏显示视图不起作用

问题描述

我试图呈现一个从底部到顶部显示的视图。这是我的代码

let myPageViewController = storyboard?.instantiateViewController(withIdentifier: "myPageViewControllerID") as! MyPageViewController
myPageViewController.modalPresentationStyle = .fullScreen
let navController = UINavigationController(rootViewController: myPageViewController)
navigationController?.present(navController, animated: true, completion: nil)

尽管我正在使用.fullScreen,但视图并未全屏显示。我尝试使用 peformSegue 显示此代码的视图

self.performSegue(withIdentifier: "myPageViewSegue", sender: nil)

页面以全屏显示,但从左到右而不是从下到上。

我尝试的第三个代码是这个

let detailVC = MyPageViewController()
let navigationController = UINavigationController(rootViewController: detailVC)
navigationController.modalPresentationStyle = .fullScreen
present(detailVC, animated: true)

在这里我得到一个错误Application tried to present modally an active controller。我试图在 MyPageViewController 消失时添加 self.dismiss 但它没有帮助。

标签: iosswiftuiviewcontroller

解决方案


问题可能是你没有展示你正在展示详细 vc 的 navigationController,使用这个

'let detailVC = MyPageViewController()
let navigationController = UINavigationController(rootViewController: detailVC)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController, animated: true)'

如果问题仍然存在,请使用

navigationController.modalPresentationStyle = .overCurrentContext

推荐阅读