我正在学习用代码
在VFL中编写约束我把我的观点水平地集中在那里:
let constraintY = NSLayoutConstraint.constraintsWithVisualFormat(
"H:[superview]-(<=1)-[collaboratorView]",
options: NSLayoutFormatOptions.AlignAllCenterY,
metrics: nil,
views: ["superview":self.assetsView, "collaboratorView":collaboratorView])
但我想知道如何将约束写入topLayoutGuide
那样的故事板
autoresizingMask
我最终得到了类似的东西,但它不起作用;(
let bar = NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[collaboratorView]",
options: [NSLayoutFormatOptions.AlignAllTop],
metrics: nil,
views: ["collaboratorView":self.collaboratorView])
答案 0 :(得分:2)
您可以定义如下:
let views : [String : AnyObject] = ["collaboratorView": collaboratorView,
"topLayoutGuide": topLayoutGuide,
"bottomLayoutGuide": bottomLayoutGuide]
// 2
var allConstraints = [NSLayoutConstraint]()
// 3
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"V:[collaboratorView]-12-[topLayoutGuide]",
options: [],
metrics: nil,
views: views)
allConstraints += verticalConstraints