无法使用锚激活约束
Posted
技术标签:
【中文标题】无法使用锚激活约束【英文标题】:Unable to activate constraint with anchors 【发布时间】:2018-04-20 10:51:49 【问题描述】:所以,我正在尝试以编程方式创建一个场景视图
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
但我收到此错误消息:
由于未捕获的异常“NSGenericException”而终止应用程序,原因:“无法使用锚点激活约束 <0x1c0278700><0x1c426db40>0x1c426db40>0x1c0278700>
【参考方案1】:
dan is right,您需要将sceneView
添加为子视图,然后才能锚定它。试试这样的:
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)
【讨论】:
其实他是对的,其实我之前也试过,不知道为什么不行,反正谢谢@dan和thomas 嘿@Thomas,非常感谢您的详细回答!我和我的团队在一个问题上停留了好几天啊:/我发布了一个有趣的问题:***.com/questions/63662318/…希望您提出建议!以上是关于无法使用锚激活约束的主要内容,如果未能解决你的问题,请参考以下文章