ios - 如何在单 View 应用程序中添加 ARKit
<p><p>我正在使用 <strong>Xcode 9 Beta 和 Swift 4</strong>。 </p>
<p>创建单一 View 应用程序。如何在我的单一应用程序 View 中使用参数现实功能?
这是我的代码。这没有任何错误。但我无法在我的场景中得到任何结果。 </p>
<pre><code>import UIKit
import ARKit
import SceneKit
class ViewController: UIViewController {
@IBOutlet weak var scaneView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
let scene = SCNScene(named: "art.scnassets/ship.scn")!
scaneView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let configuration = ARWorldTrackingSessionConfiguration()
scaneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
scaneView.session.pause()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您缺少委托(delegate)方法 <strong>ARSCNViewDelegate</strong>
我认为这段代码可以正常工作并在您的场景 View 中显示结果</p>
<pre><code> import UIKit
import ARKit
import SceneKit
class ViewController: UIViewController, ARSCNViewDelegate {
@IBOutlet weak var sceneView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
sceneView.delegate = self
sceneView.showsStatistics = true
let scene = SCNScene(named: "art.scnassets/ship.scn")!
sceneView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let configuration = ARWorldTrackingSessionConfiguration()
sceneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
sceneView.session.pause()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在单 View 应用程序中添加 ARKit,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45342327/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45342327/
</a>
</p>
页:
[1]