我正在使用 Xcode 9 Beta 和 Swift 4。
创建单一 View 应用程序。如何在我的单一应用程序 View 中使用参数现实功能? 这是我的代码。这没有任何错误。但我无法在我的场景中得到任何结果。
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()
}
}
您缺少委托(delegate)方法 ARSCNViewDelegate 我认为这段代码可以正常工作并在您的场景 View 中显示结果
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()
}
}
关于ios - 如何在单 View 应用程序中添加 ARKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45342327/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |