我正在尝试将 ARKit SceneKit 视图嵌入到 Xcode 9.2 中的视图控制器中。但是,当我这样做时,我的场景正确显示,但我失去了相机的相机视图。它进入黑色背景。任何人都知道为什么以及如何解决?
import UIKit
import SceneKit
import ARKit
class ViewControllerAR: UIViewController, ARSCNViewDelegate {
@IBOutlet var sceneViewAr: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneViewAr.delegate = self
// Show statistics such as fps and timing information
sceneViewAr.showsStatistics = true
// Create a new scene
let scene = SCNScene(named: "art.scnassets/sodium.scn")!
// Set the scene to the view
sceneViewAr.scene = scene
let mainnode = scene.rootNode.childNode(withName: "mainnode", recursively: true)
mainnode?.runAction(SCNAction.rotateBy(x: 10, y: 0, z: 0, duration: 0))
let orbit = scene.rootNode.childNode(withName: "orbit", recursively: true)
orbit?.runAction(SCNAction.rotateBy(x: 0, y: 2 * 50, z: 0, duration: 100))
if let orbittwo = scene.rootNode.childNode(withName: "orbit2", recursively: true) {
orbittwo.runAction(SCNAction.rotateBy(x: 0, y: -2 * 50, z: 0, duration: 100))
}
if let orbitthree = scene.rootNode.childNode(withName: "orbit3", recursively: true) {
orbitthree.runAction(SCNAction.rotateBy(x: 0, y: 2 * 50, z: 0, duration: 100))
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}