繁体   English   中英

iOS自动版式无法同时满足约束

[英]iOS Auto Layout Unable to simultaneously satisfy constraints

我的代码段如下

    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];
    }];

如果我导航到其他视图并向后导航,

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以在调试器中捕获此错误。 <UIKit/UIView.h>列出的UIViewUIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。 此错误。**

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

任何帮助表示赞赏。

检查您的代码。 在错误堆栈中,我看到两个冲突的环境:

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

SortOptionsView无法理解,高度大小为187点或0是什么? 您可以通过以下两种方法解决此冲突:

  1. 删除一个等式;
  2. 为每个冲突地区设置优先级;

我希望我以正确的方式送你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM