在 Xcode 9.1 中将 GIF 图像添加到 SCNNode 会导致屏幕冻结

Adding GIF image to SCNNode causes screen to freeze in Xcode 9.1

我正在向 SCNNode 添加 GIF 图像,如下所示:

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)

一切看起来都很好,我可以查看带有动画的 GIF 图像。但是当我尝试使用 PopViewController 方法移动到上一个视图控制器时,我能够导航到上一个屏幕但是屏幕在那里冻结并且 none 按钮点击有效。

如果我将应用程序置于后台并再次运行,一切都会按预期进行。

我尝试在弹出之前删除 GIF 图片,但仍然有同样的问题。如果我不添加 GIF 图像,一切正常。所以问题只在于添加 GIF,我不明白为什么?

我找到了解决方案。如果我将 tempView.layer 设置为内容,它可以正常工作,而不是像下面这样的 tempView,

        let newMaterial = SCNMaterial()
        newMaterial.isDoubleSided = true
        newMaterial.diffuse.contents = tempView.layer
        plane.materials = [newMaterial]

不知道为什么,但这对我有用。