UIViewController的视图背景颜色未更改

时间:2017-06-06 08:30:52

标签: ios swift3 background-color presentviewcontroller

我有一个UIView,只在底部显示fileprivate lazy var box: UIView = { let box = UIView() box.backgroundColor = UIColor.blue return box }() ,且高度固定:

self.view

我想为视图的其余部分(override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.clear view.isOpaque = false configView() configConstraints() } )设置一个清晰的颜色。我正在从导航控制器呈现视图控制器。我正在尝试这个:

//shortened the function for better visibility
moveToolbar.on("graphic-move-stop", function (evt) {
  oldGraphicMove = (function(x){
    var obj = Object.create( x );
    obj.geometry.rings[0][0] = 42173;
    return obj;
  })(evt.graphic);
  newGraphicMove = evt.graphic;
});

子视图显示为蓝色,但视图的其余部分是不透明的白色,我需要透明才能看到上一个viewController的视图。

我能错过什么?

1 个答案:

答案 0 :(得分:0)

要拥有透明的模型视图控制器背景,您必须在呈现视图控制器时设置UIViewController providesPresentationContextTransitionStyledefinesPresentationContext属性。

示例

if let vc = self.storyboard?.instantiateViewController(withIdentifier: "YOUR_VIEW_CONTROLLER_ID") {
    vc.providesPresentationContextTransitionStyle = true
    vc.definesPresentationContext = true
    vc.modalPresentationStyle=UIModalPresentationStyle.overCurrentContext
    self.present(vc, animated: true, completion: nil)
}