简体   繁体   English

无法使用锚点激活约束

[英]Unable to activate constraint with anchors

So, I'm trying to create a sceneView programatically所以,我正在尝试以编程方式创建一个场景视图

class ViewController: UIViewController, ARSCNViewDelegate {
    var sceneView: ARSCNView = ARSCNView()
    let configuration = ARWorldTrackingConfiguration()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
        self.configuration.planeDetection = .horizontal
        self.sceneView.session.run(configuration)
        self.sceneView.delegate = self
        self.sceneView.autoenablesDefaultLighting = true
        
        //add autolayout contstraints
        self.sceneView.translatesAutoresizingMaskIntoConstraints = false
        self.sceneView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
        self.sceneView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
        self.sceneView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
        self.sceneView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true

    }
    
    func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard anchor is ARPlaneAnchor else {return}
    }
}

But I get this error message:但我收到此错误消息:

Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x1c0278700 "ARSCNView:0x10690d7e0.top"> and <NSLayoutYAxisAnchor:0x1c426db40 "UIView:0x106b14e30.top"> because they have no common ancestor.由于未捕获的异常“NSGenericException”而终止应用程序,原因:“无法使用锚点激活约束 <NSLayoutYAxisAnchor:0x1c0278700 "ARSCNView:0x10690d7e0.top"> 和 <NSLayoutYAxisAnchor:0x1c426db40 "UIView:04x306 nocommonancestorage" . Does the constraint or its anchors reference items in different view hierarchies?约束或其锚点是否引用了不同视图层次结构中的项? That's illegal.'那是非法的。

It's happens in the part \\\\add autolayout contstraints .它发生在\\\\add autolayout contstraints部分。 How can I add constraints to that element?如何向该元素添加约束?

dan is right , you need to add sceneView as a subview before you can anchor it. dan 是对的,您需要将sceneView添加为子视图,然后才能锚定它。 Try something like this:尝试这样的事情:

view.addSubview(sceneView)
sceneView.anchor(top: self.view.topAnchor, left: self.view.leftAnchor, bottom: self.view.bottomAnchor, right: self.view.rightAnchor, paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, width: 0, height: 0)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加文本字段时无法使用锚激活约束 - Unable to activate constraint with anchors while adding a textfield 无法使用 UIimageView 的锚点错误激活约束 - Unable to activate constraint with anchors error with UIimageView Xcode 11.5 更新后错误:无法使用锚激活约束 - Xcode 11.5 Post-Update Error: Unable to activate constraint with anchors 使用约束在UITableViewController中添加UIActivityIndi​​catorView时出错。 无法使用SnapKit使用锚点激活约束 - Error adding UIActivityIndicatorView in UITableViewController using constraints. Unable to activate constraint with anchors using SnapKit 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“无法使用锚点激活约束 - Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors 以编程方式约束UITextField会导致错误“无法激活约束,因为它们没有共同的祖先。” - Constraining UITextField programmatically leads to error “Unable to activate constraint because they have no common ancestor.” 无法激活约束 - Unable to Activate Constraints Azure 空间定位点无法在 Xcode 中编译 - Azure Spatial Anchors unable to compile in Xcode 如何激活先前已停用的约束? - How can I activate, previously deactivated constraint? Swift - 约束或其锚点引用不同视图层次结构中的项 - Swift - constraint or its anchors reference items in different view hierarchies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM