在这个 ViewController 中,它将呈现一个模态视图。
模态视图呈现后,如何设置后面的 View 覆盖模态视图?
第一个 View 是当前 ViewController 中的 UIImageView。
第二个 View 是另一个模态视图,在本例中,modalViewController2
将显示在第一个 View 的下方。
class ViewController: UIViewController {
@IBOutlet weak var img: UIImageView!
override func viewDidAppear() {
super.viewDidAppear()
self.modalViewController = self.storyboard!.instantiateViewController(withIdentifier: "modal") as! ModalViewController
self.modalViewController!.modalPresentationStyle = .overCurrentContext
self.present(self.modalViewController!, animated: true, completion: nil)
self.modalViewController2 = self.storyboard!.instantiateViewController(withIdentifier: "modal2") as! ModalViewController2
self.modalViewController2!.modalPresentationStyle = .overCurrentContext
self.present(self.modalViewController2!, animated: true, completion: nil)
}
}
最佳答案
首先应该在 viewDidAppear
中呈现一个 View Controller ,因为在 viewDidLoad
中 View 的层次结构尚未完成,其次你不能同时呈现 2 个模态 VC,只制作一个模态 VC 并使用 2 个 View 构建它并根据您的需要管理每个 View 的隐藏/显示的更好方法
关于ios - 是否可以在模态视图上设置 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49379525/