override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) // Pause the view's session sceneView.session.pause() }
当我关闭模态并返回到ARKit相机视图屏幕时,此代码被触发:@H_502_5@
override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // Create a session configuration let configuration = ARWorldTrackingSessionConfiguration() // Run the view's session sceneView.session.run(configuration) }
但是这段代码永远不会恢复会话.屏幕在其读取的最后一张图像上完全冻结.有任何想法吗?@H_502_5@
我将viewDidAppear代码更新为以下内容.它仍然卡在相机屏幕上,图像被冻结.@H_502_5@
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)的自述文件:@H_502_5@
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.@H_502_5@
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
andVirtualObjectSelectionViewController
classes use popover presentation.@H_502_5@
更详细一点:如果你暂停会话,当你的用户离开不同的全屏视图控制器时,它将不会跟踪世界.这意味着当您恢复时,放置在场景中的任何虚拟内容都不会位于您离开它的位置(相对于摄像机).@H_502_5@