thread 1:signal sigabrt 错误约束 withVisualFormat

thread 1:signal sigabrt error constraints withVisualFormat

我正在设计我的视频应用程序,我不使用 main.storyboard 进行设计,只使用 viewcontroller.swift 中的代码 xcode 8 swift 3 我的问题是在我将下面的行添加到 viewcontroller.swift 之后:

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

首先确保您将 thumbnailImageView 添加为当前视图的子视图然后我认为问题是 "V: |" 之间存在 space 将其更改为 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]))