簡體   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