gpt4 book ai didi

iOS 自动布局无法同时满足约束

转载 作者:行者123 更新时间:2023-11-29 02:58:48 25 4
gpt4 key购买 nike

我的代码片段如下

    self.sortOptionsViewSmall.hidden = !self.sortOptionsViewSmall.hidden;
self.sortOptionsView.hidden=YES;
[UIView animateWithDuration:0.4 animations:^{

**self.sortViewHeightSmall.constant = (self.sortViewHeightSmall.constant == 0) ? 187 : 0;**
self.sortViewHeightConstraint.constant = (self.sortViewHeightSmall.constant == 187) ? 187 : 0;
self.tableViewHeightConstraint.constant = self.sortViewHeightSmall.constant == 0 ? 664 : 477;

[self.view layoutIfNeeded];
}];

如果我导航到其他 View 并返回

self.sortViewHeightSmall.constant = (self.sortViewHeightSmall.constant == 0) ? 187 : 0;

给我下面的错误

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:0x181643e0 V:[SortOptionsView:0x18162970(187)]>",
"<NSLayoutConstraint:0x18162ac0 V:[SortOptionsView:0x18162010(0)]>",
"<NSLayoutConstraint:0x18155170 V:[SortOptionsView:0x18162970]-(0)-
[UITableView:0xea98e00]>",
"<NSLayoutConstraint:0x181551a0 V:[SortOptionsView:0x18162010]-(0)-
[UITableView:0xea98e00]>",
"<NSLayoutConstraint:0x18155260 V:[UIView:0x181544e0]-(0)-
[SortOptionsView:0x18162010]>",
"<NSLayoutConstraint:0x18155290 V:[UIView:0x181544e0]-(0)-
[SortOptionsView:0x18162970]>"
)

将尝试通过打破约束来恢复

<NSLayoutConstraint:0x181643e0 V:[SortOptionsView:0x18162970(187)]>

中断objc_exception_throw在调试器中捕获它。UIConstraintBasedLayoutDebugging 中的方法类别 UIView列于 <UIKit/UIView.h>也可能有帮助。这个错误。**

我尝试使用 setTranslatesAutoresizingMaskIntoConstraints:NO但它不起作用。

感谢任何帮助。

最佳答案

检查你的代码。在错误堆栈中,我看到两个有冲突的约束:

"<NSLayoutConstraint:0x181643e0 V:[SortOptionsView:0x18162970(187)]>",
"<NSLayoutConstraint:0x18162ac0 V:[SortOptionsView:0x18162010(0)]>",

SortOptionsView无法理解,高度尺寸187点还是0?您可以通过两种方式解决此冲突:

  1. 删除一个约束;
  2. 为每个冲突约束设置优先级;

希望我让您走上了正确的道路。

关于iOS 自动布局无法同时满足约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23535597/

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