【问题标题】:How can I show a modal screen in swift5?如何在 swift 5 中显示模态屏幕?
【发布时间】:2019-09-20 10:11:22
【问题描述】:

我目前正在做 iOS 项目。

我的问题是,当我看到新屏幕时,我看不到旧屏幕,我只看到新屏幕。

我想要一个模态屏幕。我错过了什么?

移动模态屏幕

    func callAlert(_ text: String!) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let myAlert = storyboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
        myAlert.modalPresentationStyle = .overCurrentContext
        myAlert.modalTransitionStyle = .crossDissolve
        myAlert.text = text
        self.present(myAlert, animated: false, completion: nil)
    }

modalScreenController

class ModalViewController : UIViewController {

    var text: String?


    @IBOutlet weak var modalCustomAlert: UITextView!
    @IBOutlet weak var okButton: UIButton!

    @IBAction func okPress(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        modalCustomAlert.layer.cornerRadius = 8
        self.modalCustomAlert.text = text
    }
...

模态故事板

【问题讨论】:

    标签: ios swift screen modalviewcontroller


    【解决方案1】:

    您需要在视图控制器的视图中设置带有 alpha 分量的背景颜色。

    class ModalViewController : UIViewController {
    
        var text: String?
    
    
        @IBOutlet weak var modalCustomAlert: UITextView!
        @IBOutlet weak var okButton: UIButton!
    
        @IBAction func okPress(_ sender: Any) {
            self.dismiss(animated: true, completion: nil)
        }
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5) //Your desired color and alpha component
            modalCustomAlert.layer.cornerRadius = 8
            self.modalCustomAlert.text = text
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-21
      • 2023-01-23
      • 2020-05-06
      • 2021-03-28
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      • 2020-10-09
      相关资源
      最近更新 更多