cocoa - 自动布局中是否存在隐藏约束
问题描述
我有一个完美的复杂布局。现在我想用一个可调整大小的视图覆盖现有布局,例如 40 像素边距,相对于窗口。当我向内容视图添加一个空的自定义视图时,约束系统变得混乱并说它不能满足约束,结果非常随机。
我将视图添加为:
contentView.addSubview(customView)
let dict = ["CustomView" : customView]
let s1 = "|-(40)-[CustomView]-(40)-|"
let s2 = "V:|-(40)-[CustomView]-(40)-|"
let con1 = NSLayoutConstraint.constraints(withVisualFormat: s1, options: [],
metrics: nil, views: dict as [String : Any])
let con2 = NSLayoutConstraint.constraints(withVisualFormat: s2, options: [],
metrics: nil, views: dict as [String : Any])
viewLayout.append(contentsOf: con1)
viewLayout.append(contentsOf: con2)
NSLayoutConstraint.activate(viewLayout)
据我所知,这个视图不应该对底层内容视图的大小或形状添加额外的约束,而应该简单地调整到适当的大小。似乎必须是对视图的一些隐式约束,以防止它被简单地调整大小,或者我错过了一些关于约束的基本内容。
解决方案
我得到了这个工作。我需要取消选中自定义视图的“将掩码转换为约束”复选框。
推荐阅读
- python - 没有找到和加载 django 静态文件
- python - Teradataml 错误 mlengine_alias_definitions_v1.0' 未为当前 Vantage 版本“vantage1.0”定义
- python - 拆分单词并取特定单词
- html - 如何将图像嵌入到共享链接时出现的 URL
- javascript - JavaScript 字符串在使用 call 和 this 时显示为对象
- ruby-on-rails-3 - Byebug 不会在 RSpec 请求规范中的控制器中暂停
- javascript - 我们可以在 Graphql 中对查询/解析器进行分组,然后添加中间件吗?
- c# - 如何在c#中将xml文档转换为数据表
- android - TextView的尺寸在动态添加到LinearLayout后被扭曲
- jquery - 使用 Laravel、jQuery 获取所选项目并动态显示新的 html 块