在文档中:
返回满足其所包含约束的视图的大小.
好的,我在storyboard中创建了一个视图,并添加了约束:
yellowview.leading = self.view.leading
yellow view.trailing = self.view.trailing
yellow view.bottom = self.view.bottom
yelloview.height = 128
Run Code Online (Sandbox Code Playgroud)
现在我打印出来systemLayoutSizeFittingSize,我希望它是UIScreen宽度和128高度.但结果是:
====UILayoutFittingCompressedSize==
(0.0, 128.0)
====UILayoutFittingExpandedSize==
(10000.0, 128.0)
Run Code Online (Sandbox Code Playgroud)
======================================
然后我创建一个视图并通过代码添加约束:
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
}
Run Code Online (Sandbox Code Playgroud)
它显示很好:
现在打印出来了systemLayoutSizeFittingSize:
=====UILayoutFittingExpandedSize==
(30.0, 34.0)
===UILayoutFittingCompressedSize==
(30.0, 34.0)
Run Code Online (Sandbox Code Playgroud)
我希望它的UIScreen大小:100.
为什么我会得到这些奇怪的价值观?或者我误解了这份文件?
| 归档时间: |
|
| 查看次数: |
1582 次 |
| 最近记录: |