离开增强现实视图后删除 _SCNSnapshotWindow

Delete _SCNSnapshotWindow after leaving Augmented Reality View

当离开我的增强现实视图控制器时,这些 _SCNSnapshotWindow 对象仍然存在于我的屏幕左上角并阻止我与它们下面的任何对象交互,在我的例子中是我的 return到主菜单按钮。 有人知道我怎样才能摆脱这些对象吗?

当我使用 UIView 的实例(在我的例子中,子类)作为场景中 SCNPlane 上的漫反射 material 内容时,我遇到了类似的问题。

虽然 UIView use as material 内容被广泛报道(这里和网络上的其他地方)有效,但官方 Apple documentation for the material contents

中明显没有

在查看了上面的官方文档后,我决定切换到一个记录的(阅读:支持的)方法——在我的例子中是 UIImage——问题就消失了。这并不意味着你不能继续使用 UIView,也许这对我的做法来说是独一无二的,但在将视图指定为material 内容:

class MyCustomView: UIView {
    func renderAsImage() -> UIImage {
        let renderer = UIGraphicsImageRenderer(bounds: bounds)
        return renderer.image { context in
            layer.render(in: context.cgContext)
        }
    }
}

然后在设置SCNPlane material内容时,使用:

if let view = UINib(nibName: "MyCustomView", bundle: nil).instantiate(withOwner: self, options: nil).first as? MyCustomView {
    plane.firstMaterial!.diffuse.contents = view.renderAsImage()
}

我今天遇到了同样的问题,我的解决方法如下(是的,我已经通过它的框架尺寸搜索了 window,不要太苛刻地判断我:D ):

UIApplication.shared.windows.forEach {
        if [=10=].frame.width == 300 && [=10=].frame.height == 300 {
            print([=10=])
            [=10=].isHidden = true
        }
    }

我在我的 VC viewWillDisappear 函数上调用了它,它解决了这个问题。我确信它可以表现得更好,但我将不得不更深入地研究它。希望对你有帮助。