2017-06-20 63 views
1

我试图从模式控制器呈现自定义视图,但是当我这样做时,除了文本框之外的所有内容的背景都变为黑色,如here中所示。 (the intended modalSwift模式视图背景在设置为清除后出现黑色

这似乎是一个相当普遍的问题,但是我已经执行,大多数类似的问题提出的答案

这里的代码是在第一个控制器我的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) 
} 

任何帮助搞清楚我失踪将不胜感激。如果它有所作为,我正在使用单独的xib文件创建我的应用程序,而不是故事板。

+0

灿提供更多信息?你有没有试过self.present ...?也设置self.modalPresentationStyle 通常isOpaque和backgroundColor应设置viewDidLoad,但我不认为这是你的问题 – Jeremie

回答

5

你需要设置newEventController的modalPresentationStyle不是navigationController这样的:

newEventViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext 

此外,虽然不需要我将提出从自我,而不是导航控制器是这样的:你

self.present(newEventViewController, animated: true, completion: nil) 
+0

谢谢你现在按预期工作! –

+0

轰炸目标..谢谢。 @ChristopherKonopka - 请将此标记为已接受的答案。 – GKK