我正在开发一个ARKit项目,当在水平平面上点击时,它需要波纹动画效果。为此,我采用了UIView对象并将其作为SCNPlane对象材料的内容传递。我已将Ripple动画添加到UIView对象。一切正常。但是我无法将SCNPlane颜色更改为透明颜色。我可以为材料使用透明度属性。但是它也隐藏了Ripple动画。因此,我在这里需要的是SCNPlane对象的背景颜色应该是透明的,并且只有波纹动画可以显示给用户。有人可以帮我吗。
这是我的代码。
let location = tapGesture.location(in: self.sceneView)
let results = self.sceneView.hitTest(location, types: .existingPlane)
if !results.isEmpty{
guard let result = results.first else{ return }
let myUIView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 300, height: 300)))
myUIView.backgroundColor = .red
let plane = SCNPlane(width: 1.0, height: 1.0)
plane.firstMaterial?.diffuse.contents = myUIView
let planeViewNode = SCNNode(geometry: plane)
planeViewNode.eulerAngles.x = Float(-Double.pi / 2)
planeViewNode.position = SCNVector3(result.worldTransform.columns.3.x, result.worldTransform.columns.3.y, result.worldTransform.columns.3.z)
self.sceneView.scene.rootNode.addChildNode(planeViewNode)
//Ripple animation code goes here
}
查看此答案:How to render a UIView with transparent background on an SCNPlane in ARKit?。设置UiView isOpaque false对我有用。