How to put ARSCNView in Tabview controller without

2019-04-09 18:39发布

I am trying to implement ARKit of iOS 11 beta in my app(Tabbed application). But as said in ARKit Session Paused and Not Resuming thread, whenever i change the tab to another view controller and come back, the ARSession is getting freezed and not resuming.

Is it possible to implement ARSCNView in a tabbed application so that if you come back i can resume the ARSession? If so how to do it?

1条回答
贪生不怕死
2楼-- · 2019-04-09 18:57

Yes, you can:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    let configuration = ARWorldTrackingSessionConfiguration()
    sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
}
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    sceneView.session.pause()
}

Stop session when view will disappear, and rerun session with clearing anchors and resetting tracking when view will appear. Also to avoid appearing and disappearing ASCNView better to use popup view controllers.

For better user experience, see how Apple did those popover screens in their demo project

查看更多
登录 后发表回答