我正在尝试为“聊天气泡式”视图设置约束。
我的问题是当设备旋转时,视图没有扩展到设备宽度的 70%。
这是一张图片来演示正在发生的事情。
当我水平旋转设备时,注意右侧设备上的蓝色气泡可能会扩展到占据 70% 的空间,相反,它保持当前的窄宽度:
现在,这是我想要发生的事情的图片。当我旋转设备时,您是否看到右侧的设备实际上将我的自定义视图扩展到了屏幕的 70%?
我做错了什么?如何实现第二张图片中的行为?
这是我使用 SnapKit DSL 布置自定义视图的代码:
bubble.snp.makeConstraints { (make) in
make.width.lessThanOrEqualToSuperview().multipliedBy(0.7).priority(.required)
make.top.right.equalToSuperview().inset(20)
}
In case you are curious, here is a link to a GitHub Gist of my custom bubble
view.
非常感谢任何帮助!
编辑:我更新的代码:
bubble.snp.makeConstraints { (make) in
make.width.lessThanOrEqualToSuperview().multipliedBy(0.7).priority(.required)
make.width.equalToSuperview().multipliedBy(0.7).priority(.low)
make.top.right.equalToSuperview().inset(20)
}