如何在ViewController2.swift类的overCurrentContext视图中显示图像?

问题描述 投票:0回答:1

如何在ViewController2.swift类的overCurrentContext视图中显示图像?我在手动工作时正确地执行此操作,但在swift中以编程方式使用此操作时却没有这样做。

ViewController1.swift代码 -

    @IBAction func btnImage(_ sender: Any)
        {
            let imageVC = self.storyboard?.instantiateViewController(withIdentifier: "ImageVC") as! ImageVC
            self.navigationController?.pushViewController(imageVC, animated: true)
        }

ViewController2.swift代码 -

override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationController?.setNavigationBarHidden(true, animated: true)
        self.navigationController?.modalPresentationStyle = .overCurrentContext

    }

我想要这个背景alpha 0.7并使用.overCurrentContext

输出 -

ios swift uinavigationcontroller uimodalpresentationstyle
1个回答
0
投票

你正在推动你的viewController,而你应该用modalPresentationStyle .overCurrentContext呈现它。做这样的事情:

@IBAction func btnImage(_ sender: Any)
    {
    let vc = self.storyboard?.instantiateViewController(withIdentifier: "ImageVC") as! ImageVC
    vc?.view.backgroundColor = UIColor.black.withAlphaComponent(0.7)
    vc?.modalPresentationStyle = .overCurrentContext
    vc?.navigationController?.isNavigationBarHidden = true
    self.navigationController?.present(vc, animated: true, completion: nil)
}

有关更多信息,您可以在Apple Docs中阅读有关modalPresentationStyle的更多信息。希望能帮助到你!!

© www.soinside.com 2019 - 2024. All rights reserved.