I've created AR app which detects image, upon image detection I want to play gif on top of it.
I followed this tutorial to detect image: https://www.raywenderlich.com/6957-building-a-museum-app-with-arkit-2
In VC I added Imageview like this:
var imageView = GIFImageView(frame: CGRect(x: 0, y: 0, width: 600, height: 600))
Here is my code in ARSCNViewDelegate didAdd node for method.
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
DispatchQueue.main.async { self.instructionLabel.isHidden = true }
if let imageAnchor = anchor as? ARImageAnchor {
// handleFoundImage(imageAnchor, node)
let size = imageAnchor.referenceImage.physicalSize
DispatchQueue.main.async(){ // If we remove this we are getting UIview setAnimation is being call from background thread error is coming.
self.imageView.animate(withGIFNamed: "tenor.gif") // I actually access gif from Document folder i.e Data format
}
let imgMaterial = SCNMaterial()
imgMaterial.diffuse.contents = imageView
let imgPlane = SCNPlane(width: size.width, height: size.height)
imgPlane.materials = [imgMaterial]
let imgNode = SCNNode(geometry: imgPlane)
imgNode.eulerAngles.x = -.pi / 2
node.addChildNode(imgNode)
node.opacity = 1
}
}
After playing gif when I go back to my previous/next/same VC I can't tap on any UI elements(buttons etc).
In console I see this but I did not find solution to this. view animation is there in UIImage+gif swift file.
UIView setAnimationsEnabled being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior
Just run this in Device. https://drive.google.com/file/d/1FKHPO6SkdOEZ-w_GFnrU5CeeeMQrNT-h/view?usp=sharing
You just run this project in device and scan dinosaur.png image(added ion xcode) you will gif playing on top of it. Once if you go back to firstVC that's all app is freezed you can't tap on any button in First VC and also hyou can't start AR scene again. I can't figure out this issue why it's happening after palying GIF can you pleach check and let me know.
If anything is required please let me know.. Thanks in advance.