如何在 ARKit 中的 SCNPlane 上渲染具有透明背景的 UIView?

How to render a UIView with transparent background on an SCNPlane in ARKit?

我的 UIView 有一个 UIColor.clear 背景。我正在从情节提要中实例化视图控制器。

当我将 SCNPlane 几何体的漫反射内容设置为 viewcontroller 的视图时,透明背景在平面上显示为纯白色。 这是我的设置方式

let material = SCNMaterial()
material.diffuse.contents = viewController.view
planeGeometry.materials = [material]

能看到视图,只是背景不透明

我在其他 Stack overflow 帖子上看到了他们建议尝试这个的建议

material.diffuse.contents = viewController.view.layer

这有效,并且平面渲染了透明胶片,但随后视图不再具有交互性。

有什么方法可以在平面上渲染视图时保持交互性和透明度?

尝试将视图的 isOpaque 属性 设置为 false:

let material = SCNMaterial()
viewController.view.isOpaque = false
material.diffuse.contents = viewController.view
planeGeometry.materials = [material]