根据文档,约束实例属性是
视图所持有的约束。
var constraints: [NSLayoutConstraint] { get }
但是当我用
创建它们时 SampleView.rightAnchor.constraint(equalTo: right ,constant: rightConstant).isActive = true
所以它给我打印了一个约束
<NSLayoutConstraint:0x1c4281540 UIButton:0x103d1d030'Next'.right == UIView:0x103d04740.right (active)>
但约束属性没有显示任何内容。空数组[],但同时 当我定义像heightAnchor和widthAnchor
这样的约束时 sampleView.heightAnchor.constraint(equalToConstant: 50).isActive = true
sampleview.widthAnchor.constraint(equalToConstant: 60).isActive = true, and constraints array is not empty
[<NSLayoutConstraint:0x1c028bd10 UIButton:0x103d1c5e0'Skip'.height == 50 (active)>,
<NSLayoutConstraint:0x1c028bf40 UIButton:0x103d1c5e0'Skip'.width == 60 (active)>]
如果有人知道,为什么会这样?