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

问题描述 投票:2回答:1

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

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看起来很好,我可以用动画查看GIF图像。但是当我尝试使用PopViewController方法移动到以前的视图控制器时,我能够导航到上一个屏幕,但屏幕冻结在那里,按钮点击都不起作用。

如果我将应用程序放在后台并再次出现,那么一切都按预期工作。

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

ios11 scenekit augmented-reality arkit xcode9.1
1个回答
2
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.