设置它清除后,迅速模态视图背景出现黑色

Chr*_*pka 2 modalviewcontroller ios swift swift3

我想从一个控制器模态呈现自定义视图,但是当我这样做的一切的背景,但在可见的文本字段我有变黑这里.(预期模式)

这似乎是一个相当普遍的问题,但是我已经实现了大多数类似问题作为答案的代码

这是我在第一个控制器中的addEvent方法:

@IBAction func addEvent(_ sender: Any) {
    let newEventViewController = NewEventViewController()
    newEventViewController.view.backgroundColor = UIColor.clear
    newEventViewController.view.isOpaque = false
    navigationController?.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
    navigationController?.present(newEventViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

任何帮助搞清楚我缺少的东西将不胜感激.如果它有所作为我使用单独的xib文件而不是故事板创建我的应用程序.

Uph*_*uth 11

你需要设置newEventController的modalPresentationStyle而不是navigationController,如下所示:

newEventViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
Run Code Online (Sandbox Code Playgroud)

虽然不需要我会从自己而不是导航控制器呈现如下:

self.present(newEventViewController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)