ARView 黑屏
Black screen on ARView
我正在尝试以编程方式实例化 ARView。这是我的视图控制器代码
import Foundation
import UIKit
import RealityKit
class ARViewController: UIViewController {
var arView: ARView = {
let arview = ARView()
arview.cameraMode = .ar
arview.automaticallyConfigureSession = true
arview.translatesAutoresizingMaskIntoConstraints = false
return arview
}()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
setupUIConstraints()
}
func setupUI() {
view.addSubview(arView)
// Load the "Cupcake" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
}
func setupUIConstraints() {
view.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
view.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
view.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
view.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
}
}
该应用程序会适当地向我询问相机权限,但即使接受后,'view' 也只是黑屏。我在 iPhone XS 上,并将 arkit 导入我的 info.plist。任何帮助将不胜感激。
在 setupUIConstraints
中,您将 ARViewController.view 的约束设置为它自己的约束,而不是 ARView。
换成ARView应该就可以了!
我正在尝试以编程方式实例化 ARView。这是我的视图控制器代码
import Foundation
import UIKit
import RealityKit
class ARViewController: UIViewController {
var arView: ARView = {
let arview = ARView()
arview.cameraMode = .ar
arview.automaticallyConfigureSession = true
arview.translatesAutoresizingMaskIntoConstraints = false
return arview
}()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
setupUIConstraints()
}
func setupUI() {
view.addSubview(arView)
// Load the "Cupcake" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
}
func setupUIConstraints() {
view.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
view.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
view.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
view.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
}
}
该应用程序会适当地向我询问相机权限,但即使接受后,'view' 也只是黑屏。我在 iPhone XS 上,并将 arkit 导入我的 info.plist。任何帮助将不胜感激。
在 setupUIConstraints
中,您将 ARViewController.view 的约束设置为它自己的约束,而不是 ARView。
换成ARView应该就可以了!