本文介绍了以编程方式添加 ARSCNView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式添加 ARSCNView?如何设置宽度、高度和约束?

How can I add a ARSCNView programmatically? How can I set width, height and constraints?.

class ViewController: UIViewController {

    var sceneView: ARSCNView!
    let configuration = ARWorldTrackingConfiguration()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
        self.sceneView.session.run(configuration)
    }
}

推荐答案

如果你只是问如何添加 ARSCNView,那么我的回答是:

If you are just asking about how to add ARSCNView, then my answer would be:

//instantiate scene view in viewDidLoad
sceneView = ARSCNView()

//add it to parents subview
self.view.addSubview(sceneView)

//add autolayout contstraints
sceneView.translatesAutoresizingMaskIntoConstraints = false
sceneView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
sceneView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
sceneView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
sceneView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true

//load your scene

这篇关于以编程方式添加 ARSCNView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-14 22:17