Reputation: 1823
I am adding GIF image to SCNNode like below:
let plane = SCNPlane(width: 2, height: 2)
let bundleURL = Bundle.main.url(forResource: "engine", withExtension: "gif")
let animation : CAKeyframeAnimation = createGIFAnimation(url: bundleURL!)!
let layer = CALayer()
layer.bounds = CGRect(x: 0, y: 0, width: 900, height: 900)
layer.add(animation, forKey: "contents")
let tempView = UIView.init(frame: CGRect(x: 0, y: 0, width: 900, height: 900))
tempView.layer.bounds = CGRect(x: -450,
y: -450,
width: tempView.frame.size.width,
height: tempView.frame.size.height)
tempView.layer.addSublayer(layer)
let newMaterial = SCNMaterial()
newMaterial.isDoubleSided = true
newMaterial.diffuse.contents = tempView
plane.materials = [newMaterial]
let node = SCNNode(geometry: plane)
node.name = "engineGif"
let gifImagePosition = SCNVector3Make((self.virtualObjectInteraction.selectedObject?.childNodes[0].position.x)! + 2,
(self.virtualObjectInteraction.selectedObject?.childNodes[0].position.y)! + 4,
(self.virtualObjectInteraction.selectedObject?.childNodes[0].position.z)! - 2))
node.position = gifImagePosition
self.virtualObjectInteraction.selectedObject?.childNodes[0].addChildNode(node)
Everthing looks fine and I am able to view the GIF image with animation. But when I try to move to previous view controller using PopViewController method, I am able to navigate to previous screen but the screen freezes there and none of the button click works.
If I put the app in background and come again, everything works as intended.
I tried removing the GIF image before pop but still have same issue. If I don't add the GIF image, everything is working fine. So the issue is only with adding GIF and I couldn't figure out why?
Upvotes: 2
Views: 604
Reputation: 1823
I found the solution. If i set tempView.layer as contents, it is working fine instead of tempView like below,
let newMaterial = SCNMaterial()
newMaterial.isDoubleSided = true
newMaterial.diffuse.contents = tempView.layer
plane.materials = [newMaterial]
Do not know why it is but this worked for me.
Upvotes: 2