ios – ARKit会话已暂停且未恢复

在我的ARKit应用程序中,我提出了一个模态窗口.当我关闭模态并返回到ARSCNView时,我发现由于此代码会话暂停:
override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

        // Pause the view's session
        sceneView.session.pause()
    }

当我关闭模态并返回到ARKit相机视图屏幕时,此代码被触发:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // Create a session configuration
        let configuration = ARWorldTrackingSessionConfiguration()

        // Run the view's session
        sceneView.session.run(configuration)
    }

但是这段代码永远不会恢复会话.屏幕在其读取的最后一张图像上完全冻结.有任何想法吗?

我将viewDidAppear代码更新为以下内容.它仍然卡在相机屏幕上,图像被冻结.

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // Create a session configuration
        let configuration = ARWorldTrackingSessionConfiguration()

        sceneView.session.delegate = self

        if self.isPaused {
            sceneView.session.run(sceneView.session.configuration!)
        } else {
            // Run the view's session
            sceneView.session.run(configuration)
        }


    }

解决方法

不确定为什么你的会话没有恢复,但是…这通常不是你想要的情况.

请注意随附Apple的ARKit示例代码(附于WWDC17 session on ARKit)的自述文件:

Avoid interrupting the AR experience. If the user transitions to another fullscreen UI in your app,the AR view might not be an expected state when coming back.

Use the popover presentation (even on iPhone) for auxiliary view controllers to keep the user in the AR experience while adjusting settings or making a modal selection. In this example,the SettingsViewController and VirtualObjectSelectionViewController classes use popover presentation.

更详细一点:如果你暂停会话,当你的用户离开不同的全屏视图控制器时,它将不会跟踪世界.这意味着当您恢复时,放置在场景中的任何虚拟内容都不会位于您离开它的位置(相对于摄像机).

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...