将具有透明度的 UIView(来自 xib)添加到 SceneKit [英] Add UIView (from xib) with transparency to SceneKit

查看:27
本文介绍了将具有透明度的 UIView(来自 xib)添加到 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)
}

我保留了各种不同的东西,例如分配了 0.2 不透明度的 blendMode、backgroundColor 以及整个视图,因为这些都是我尝试过的事情,但仍然获得白色背景,其中一些视图元素位于顶部白色很淡.也试过 blendMode = .alpha 发现没有区别.这里的'self'是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆