我试图呈现一种从下到上展示的视图。这是我的代码
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,但没有帮助。
发布于 2019-10-11 19:42:16
问题可能是你没有展示navigationController,你展示的是细节vc,使用这个
'let detailVC = MyPageViewController()
let navigationController = UINavigationController(rootViewController: detailVC)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController, animated: true)'
如果问题仍然存在,请使用
navigationController.modalPresentationStyle = .overCurrentContext
发布于 2019-10-14 11:27:33
你可以试试这个,对我很管用:
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
}
发布于 2019-10-11 19:20:48
试试这个:
let detailVC = MyPageViewController()
detailVC.modalPresentationStyle = .fullScreen
present(detailVC, animated: true)
https://stackoverflow.com/questions/58340092
复制相似问题