2017-07-29 89 views
0

我正在设计我的视频应用程序,并且我不使用main.storyboard进行设计,只在xcode 8中使用viewcontroller.swift中的代码swift 3 我的问题是在添加下面的行之后viewcontroller.swift:线程1:信号sigabrt错误约束withVisualFormat

addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H: |-16-[v0]-16-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": thumbnailImageView])) 
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V: |-16-[v0]-16-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": thumbnailImageView])) 

我没有任何错误,但我跑项目后的崩溃,给我这个错误在appdelegate.swift: appdelegate.swift error

请帮我这个

这是我的project source code download link

+0

检查如果你的thumbnailImageView被添加为子视图添加约束之前是一个常见的错误 –

回答

1

首先确保你将thumbnailImageView作为子视图添加到当前视图中,然后我认为问题是“V:|”之间存在空格。将其更改为V:| ,对H:|做同样的事情。你的约束应该是这样的

addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]-16-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": thumbnailImageView])) 
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-16-[v0]-16-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": thumbnailImageView]))