ios - Swift 编程自动布局约束问题

标签 ios swift autolayout constraints nslayoutconstraint

我只是在用

toolBar.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0).isActive = true 

用于设置我的 topAnchor。

但是,当我将常量从 0 更改为实际数字时,控制台会给我

[LayoutConstraints] Unable to simultaneously satisfy constraints.

这个错误。 我在 viewDidLoad 中调用此约束,但将其更改为 viewWillLayoutSubviews 或其他部分无法解决问题。

如何修复此错误? 谢谢!

最佳答案

因为你创建了另一个,所以你需要编辑当前的

var topCon:NSLayoutConstraint!

topcon = toolBar.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0)

topCon.isActive = true

然后玩常量

topCon.constant = // anyNumber

关于ios - Swift 编程自动布局约束问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52907130/

相关文章:

ios - UIDatePicker 最小和最大高度

ios - TypeKit vs NSAttributedString - 在创建样式标签时,我可以使用 TextKit 代替 NSAttributedString 吗?

ios - UIImage 从 json 请求返回 nil 到 tableView 单元格图像的 mysql 数据库?

ios - 如何将 init 用于从 Storyboard 中加载的 View Controller ?

ios - iOS8 上的自动布局错误,但 iOS9 上没有

ios - 自动布局 : auto update constraints when some view is empty

ios - 在 UITableViewCell 中绘制一个彩色圆圈

ios - 不确定如何使用 CICrop 裁剪图像

ios - Xcode仪器可以在真正的Apple Watch设备上运行吗?

iOS Delegate 返回 nil (Swift)