【问题标题】:Adding GIF image to SCNNode causes screen to freeze in Xcode 9.1将 GIF 图像添加到 SCNNode 会导致屏幕在 Xcode 9.1 中冻结
【发布时间】:2018-04-19 13:01:07
【问题描述】:

我正在向 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 方法移动到上一个视图控制器时,我能够导航到上一个屏幕,但屏幕冻结在那里,并且没有任何按钮单击工作。

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

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

【问题讨论】:

    标签: ios11 scenekit augmented-reality arkit xcode9.1


    【解决方案1】:

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

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

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

    【讨论】:

    • 我有同样的问题,因为我加载了一个 UIView 但在我的情况下我无法使用图层任何想法?
    • 我可以在 UIView 中进行交互。但是顶部导航栏不起作用。你有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 2020-04-19
    • 2019-04-22
    • 1970-01-01
    • 2019-08-11
    • 2021-09-29
    • 2017-01-22
    • 1970-01-01
    相关资源
    最近更新 更多