【发布时间】:2020-06-14 16:31:40
【问题描述】:
我已经创建了检测图像的 AR 应用,在检测到图像后,我想在它上面播放 gif。
我按照这个教程来检测图像:https://www.raywenderlich.com/6957-building-a-museum-app-with-arkit-2
在 VC 中我像这样添加了 Imageview:
var imageView = GIFImageView(frame: CGRect(x: 0, y: 0, width: 600, height: 600))
这是我在 ARSCNViewDelegate didAdd 节点中用于方法的代码。
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
}
}
播放 gif 后,当我回到上一个/下一个/相同的 VC 时,我无法点击任何 UI 元素(按钮等)。
在控制台中我看到了这个,但我没有找到解决方案。视图动画在 UIImage+gif swift 文件中。
从后台线程调用 UIView setAnimationsEnabled。不支持从后台线程对 UIView 或子类执行任何操作,这可能会导致意外和隐蔽行为
只需在设备中运行它。 https://drive.google.com/file/d/1FKHPO6SkdOEZ-w_GFnrU5CeeeMQrNT-h/view?usp=sharing
您只需在设备中运行此项目并扫描恐龙.png 图像(添加 ion xcode),您将在其上播放 gif。一旦你回到firstVC,所有的应用程序都被冻结了,你不能点击First VC中的任何按钮,你也不能再次启动AR场景。 我无法弄清楚为什么在播放 GIF 后会发生这个问题,你能检查一下并告诉我。
如果有什么需要请告诉我。提前谢谢。
【问题讨论】:
标签: ios swift xcode scenekit gif