我和你的情况相同,我使用协议将数据传回第一个ViewController(在你的情况下,MainViewController)告诉它隐藏模糊。
这是我如何做到的:
这是第一个ViewController(在你的例子中是MainViewController)。您可以创建并实现协议并遵循其方法。
import UIKit //here you can name your protocol and the function whatever you want and set the values you want to pass back, in our case a boolean protocol esconderBlurProtocol { func isEsconder(value: Bool) } //you have to extend the controller to your protocol and conform its methods, in this case the function isEsconder, and inside it you do whatever you want. //In our case hide the blur if the value we are receiving is true class PalestrantesVC: UIViewController,esconderBlurProtocol { func isEsconder(value: Bool) { if(value){ blur.isHidden = true } } }
现在为您的第二个ViewController,它非常简单。只需创建一个协议类型的变量(在我的例子中,esconderBlurProtocol)。
class DetalhePalestranteVC: UIViewController { var delegate: esconderBlurProtocol?
并且在你需要时使用它调用它的函数(在我们的例子中,当我们关闭这个ViewController时),将值True发送回我们之前的ViewController:
override func viewWillDisappear(_ animated: Bool) { delegate?.isEsconder(value: true) }
要完成,您必须在打开第二个ViewController时将协议实例设置为第一个ViewController,如下所示:
let viewController = (self.storyboard?.instantiateViewController(withIdentifier: "DetalhePalestranteVC")) as! DetalhePalestranteVC viewController.modalPresentationStyle = .overFullScreen viewController.delegate = self self.present(viewController, animated: true, completion: nil)
而已。对不起,如果它凌乱,因为英语不是我的主要语言。
呼叫 blurEffectView?.removeFromSuperview 内 viewWillDisappear() 要么 viewDidDisappear 来自 的 的viewController 强> 的 的 弹出 强>
blurEffectView?.removeFromSuperview
viewWillDisappear()
viewDidDisappear