gpt4 book ai didi

swift - 无法同时满足约束 - 制图

转载 作者:行者123 更新时间:2023-11-30 14:03:12 25 4
gpt4 key购买 nike

我在使用 Swift 2.0 编写的应用程序上使用 AutoLayout 和代码,并使用 Cartograph 来帮助解决约束。但有些东西阻止了我的应用程序,否则,我用它以编程方式添加 View 。

func addButtonOne() -> Void {
buttonOne = UIButton()
buttonOne.backgroundColor = UIColor.greenColor()
self.view.addSubview(buttonOne)

constrain(buttonOne, view) { buttonOne, view in
buttonOne.left == view.right - 12
buttonOne.right == view.left + 12
buttonOne.bottom == view.bottom - 12
}

}

但编译后,返回:

2015-09-23 00:54:24.489 Fun With Swift[24809:2358352] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand,
refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)

(
"<NSLayoutConstraint:0x7afe2160 H:[UIView:0x7afdfe90]-(-12)-[UIButton:0x7afe13b0](LTR)>",
"<NSLayoutConstraint:0x7afe2730 UIButton:0x7afe13b0.right == UIView:0x7afdfe90.left + 12>",
"<NSLayoutConstraint:0x7b0866e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7afdfe90(320)]>"
)

有人知道我能做什么吗?这是一个不同的问题,因为我使用一个库。

最佳答案

添加约束代码应如下所示

 constrain(buttonOne, view) { buttonOne, view in
buttonOne.left == view.left + 12
buttonOne.right == view.right - 12
buttonOne.bottom == view.bottom - 12
}

如果您需要底部有一个按钮,距左右和底部有 12 pt 边距

关于swift - 无法同时满足约束 - 制图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32730830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com