将具有透明度的UIView(来自xib)添加到SceneKit [英] Add UIView (from xib) with transparency to SceneKit
问题描述
我正在尝试将具有半透明背景的UIView加载到SceneKit中,但是目前,随着我降低不透明度,它会逐渐变为白色. 我要加载到SceneKit中的.xib文件中有一个非常简单的UIView布局. 到目前为止,我可以在SCNMaterial中显示UIView,更改视图内的任何文本字段,图像等,都不会出现问题.但是,我不能让它具有透明度.如果我更改视图的Alpha,它只会淡化为白色.
I'm trying to load a UIView into SceneKit with a translucent background, but currently, it just fades to white as I decrease the opacity. I have a very simple UIView layout in a .xib file that I want to load into SceneKit. So far I can display the UIView in the SCNMaterial, change any text fields, images, etc inside the view without a problem. However, I cannot let it have transparency. If I change the alpha of the view it just fades to white.
大多数代码如下:
if let cardView = Bundle.main.loadNibNamed("OverlayCard", owner: self, options: nil)?.first as? OverlayCard {
cardView.backgroundColor = UIColor(displayP3Red: 1.0, green: 0.4, blue: 0.9, alpha: 0.2)
let newplane = SCNPlane()
let newMaterial = SCNMaterial()
cardView.alpha = 0.2
cardView.isOpaque = false
newMaterial.diffuse.contents = cardView
newMaterial.blendMode = .add
newplane.materials = [newMaterial]
let viewNode = SCNNode(geometry: newplane)
self.addChildNode(viewNode)
}
我已经完成了很多工作,例如为blendMode,backgroundColor分配了0.2的不透明度以及整个视图,因为这些都是我尝试过的事情,但是仍然获得白色背景,并且在视图顶部还包含一些视图元素白色非常淡出.还尝试了blendMode = .alpha来查找差异. 这里的自我"是SCNNode的子类.
I've left in various things like assigning the blendMode, backgroundColor with 0.2 opacity as well as the entire view because these are all things I've tried but still get a white background with some of the view's elements on top of the white very faded out. Have also tried blendMode = .alpha to find no difference. 'self' here is a subclass of SCNNode.
有人知道我如何使该视图的背景淡化为透明,而不是淡化为白色吗?或者,将视图加载到SceneKit中的另一种方法.
Does anyone know how I can make this view's background fade to transparent, rather than fade to white? Or, another way to load a view into SceneKit.
推荐答案
尝试将视图的图层设置为diffuse.contents,而不是视图本身.
Try setting the layer of the view as diffuse.contents instead of the view itself.
newMaterial.diffuse.contents = cardView.layer
这篇关于将具有透明度的UIView(来自xib)添加到SceneKit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!