在文档中:
返回满足其约束的视图的大小。
好的,我在故事板中创建了一个视图,并添加了约束:
yellowview.leading = self.view.leading
yellow view.trailing = self.view.trailing
yellow view.bottom = self.view.bottom
yelloview.height = 128
现在我打印systemLayoutSizeFittingSize
,我希望它是UIScreen
宽度和128高度。但结果是:
====UILayoutFittingCompressedSize==
(0.0, 128.0)
====UILayoutFittingExpandedSize==
(10000.0, 128.0)
======================================
然后我创建一个视图并通过代码添加约束:
let btn :UIButton = {
let btn = UIButton(type: .Custom)
btn.backgroundColor = UIColor.redColor()
btn.translatesAutoresizingMaskIntoConstraints = false
return btn
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(btn)
btn.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor, constant: 100).active = true
btn.trailingAnchor.constraintEqualToAnchor(self.view.trailingAnchor, constant: -100).active = true
btn.topAnchor.constraintEqualToAnchor(self.view.topAnchor, constant: 100).active = true
btn.bottomAnchor.constraintEqualToAnchor(self.view.bottomAnchor, constant: -100).active = true
}
很好地展示了:
现在打印systemLayoutSizeFittingSize
:
=====UILayoutFittingExpandedSize==
(30.0, 34.0)
===UILayoutFittingCompressedSize==
(30.0, 34.0)
我期望UIScreen
大小:100。
为什么我会得到这些奇怪的值?或者我误解了这份文件?