Nin*_*nja 3 layout ios nslayoutconstraint swift
根据文档,约束实例属性是
视图所具有的约束。
var constraints: [NSLayoutConstraint] { get }
Run Code Online (Sandbox Code Playgroud)
但是当我用创建它们时
SampleView.rightAnchor.constraint(equalTo: right ,constant: rightConstant).isActive = true
Run Code Online (Sandbox Code Playgroud)
所以它给我打印了一个约束
<NSLayoutConstraint:0x1c4281540 UIButton:0x103d1d030'Next'.right == UIView:0x103d04740.right (active)>
Run Code Online (Sandbox Code Playgroud)
但约束属性没有向我显示任何内容。空数组 [],但同时当我定义 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)>]
Run Code Online (Sandbox Code Playgroud)
如果有人知道,为什么会这样?
宽度和高度约束将添加到视图本身,但与 otherViews 的约束将添加到另一个视图(如果它是父视图),如果不是两个子视图之间的共享父视图,请参阅此
因此,在您询问任何视图的限制之前,您应该记住上面的照片
| 归档时间: |
|
| 查看次数: |
674 次 |
| 最近记录: |