我试图呈现一个从下至上显示的视图。这是我的代码
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,但没有帮助。
答案 0 :(得分:1)
问题可能出在您未呈现navigationController时,您正在呈现详细信息vc,请使用此
'let detailVC = MyPageViewController()
let navigationController = UINavigationController(rootViewController: detailVC)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController, animated: true)'
如果问题仍然存在,请使用
navigationController.modalPresentationStyle = .overCurrentContext
答案 1 :(得分:0)
尝试这个:
let detailVC = MyPageViewController()
detailVC.modalPresentationStyle = .fullScreen
present(detailVC, animated: true)
答案 2 :(得分:0)
您可以尝试一下,为我工作:
设置您的segue:
performSegue(withIdentifier: "myPageViewSegue", sender: self)
然后使用prepare for segue方法:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destVC = segue.destination as! MyPageViewSegue
destVC.modalPresentationStyle = .fullScreen
}
答案 3 :(得分:0)
我遇到了这个问题,被困住了。然后我意识到,覆盖dismiss
也会覆盖.fullscreen
// This breaks .fullscreen
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
super.dismiss(animated: flag, completion: completion)
// do something
}
很明显,如果使用.fullscreen
,则不需要此子,但是将其放置在适当位置会导致问题。
答案 4 :(得分:-1)
let detailVC = MyPageViewController()
let navigationController = UINavigationController(rootViewController: detailVC)
navigationController.modalPresentationStyle = .overCurrentContext
present(detailVC, animated: true, completion: nil)
说明: 非常简单。最好逐行解释它。第1行:声明视图控制器。第2行:添加导航控制器(它是可选的。如果不需要,则可以跳过导航栏)。第3行:我们已将模式表示样式链接定义为overCurrentContext。并根据您的需要显示navigationController(它将附带导航栏和viewcontroller)或仅显示viewcontroller。在这段代码中,您将获得不带导航栏的viewcontroller。