问题
I am working on a ARKit project which needs Ripple animation effect when tapped on Horizontal Plane. For that I have took UIView object and pass that as contents for material of SCNPlane object. I have added Ripple animation to UIView object. Everything works fine. But I can't change the SCNPlane colour to clear color. I can use transparency property for the material. But it is hiding Ripple animation too. So, what I need here is, the background colour of SCNPlane object should be transparent and only Ripple animation should appear to user. Can someone help me on this.
This is my code.
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
}
I took screenshot from Civilisations AR app from BBC. Please refer the screenshot by clicking this link. This is how exactly I need.
回答1:
Check out this answer. Setting the UiView
isOpaque
to false
worked for me.
来源:https://stackoverflow.com/questions/50368057/how-to-change-scnplane-color-as-clear-color