ios - 是否可以在模态视图上设置 View ?

标签 ios swift modalviewcontroller presentmodalviewcontroller

在这个 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/

相关文章:

objective-c - 操作完成后更改页面

ios - 如何在 Messages Extension 中发送 MSMessage?

iOS:当分段控件更改时隐藏或删除以编程方式添加的 subview

ios - 从纵向 View Controller 呈现模态横向 View Controller

iphone - 显示连续模态视图的正确方法

ios - UITextView 委托(delegate)多次调用

ios - 为什么我能够访问 Core Data 中除图像属性之外的所有属性? (这是二进制数据?)

swift - 需要各种 NSObject 子类型的协议(protocol),无法为 'NSObject' 返回 'Self'

php - 固定 : JSON cannot decode array from php

ios - UINavigationController自定义模态转换,导航栏太小