如何在overCurrentContext视图中显示ViewController2
.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
产出-
发布于 2018-02-28 22:31:39
您正在推动您的viewController,相反,您应该将其与viewController .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中阅读更多关于modalPresentationStyle的信息。希望能帮上忙!
https://stackoverflow.com/questions/49043214
复制相似问题