簡體   English   中英

哪些約束沖突?

[英]Which constraints are conflicting?

我有一個UICollectionViewCell,它一直給我一個錯誤的錯誤提示,因為它們與自動布局約束沖突。 以下是它聲稱在調試器中打印出的沖突約束:

(
"<NSAutoresizingMaskLayoutConstraint:0x10e47df70 h=--& v=--& UIView:0x1094594c0.width == 414   (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x10e47e110 h=--& v=--& UIView:0x1094594c0.height == 531   (active)>",
"<NSLayoutConstraint:0x10947e7e0 UIButton:0x10947e410.height == 44   (active)>",
"<NSLayoutConstraint:0x10e457fd0 UIImageView:0x10e44e960.height == 1.2*UIImageView:0x10e44e960.width   (active)>",
"<NSLayoutConstraint:0x109488520 V:|-(0)-[UIImageView:0x10e44e960]   (active, names: '|':UIView:0x10947bfd0 )>",
"<NSLayoutConstraint:0x109488610 H:[UIImageView:0x10e44e960]-(0)-|   (active, names: '|':UIView:0x10947bfd0 )>",
"<NSLayoutConstraint:0x109488700 H:|-(0)-[UIImageView:0x10e44e960]   (active, names: '|':UIView:0x10947bfd0 )>",
"<NSLayoutConstraint:0x1094890c0 V:[UIImageView:0x10e44e960]-(8)-[UITextView:0x102940a00'Hey']   (active)>",
"<NSLayoutConstraint:0x10948a520 V:[UIButton:0x10947e410]-(0)-|   (active, names: '|':UIView:0x10947bfd0 )>",
"<NSLayoutConstraint:0x10948a820 V:[UITextView:0x102940a00'Hey']-(8)-[UIButton:0x10947e410]   (active)>",
"<NSLayoutConstraint:0x10948ae00 V:|-(5)-[UIView:0x10947bfd0]   (active, names: '|':UIView:0x109452f60 )>",
"<NSLayoutConstraint:0x10948af40 H:|-(5)-[UIView:0x10947bfd0]   (active, names: '|':UIView:0x109452f60 )>",
"<NSLayoutConstraint:0x10948b030 V:[UIView:0x10947bfd0]-(5)-|   (active, names: '|':UIView:0x109452f60 )>",
"<NSLayoutConstraint:0x10948b120 H:[UIView:0x10947bfd0]-(5)-|   (active, names: '|':UIView:0x109452f60 )>",
"<NSLayoutConstraint:0x10948b500 H:[UIView:0x109452f60]-(0)-|   (active, names: '|':UIView:0x1094594c0 )>",
"<NSLayoutConstraint:0x10948b640 H:|-(0)-[UIView:0x109452f60]   (active, names: '|':UIView:0x1094594c0 )>",
"<NSLayoutConstraint:0x10948b730 V:|-(0)-[UIView:0x109452f60]   (active, names: '|':UIView:0x1094594c0 )>",
"<NSLayoutConstraint:0x10948b820 V:[UIView:0x109452f60]-(0)-|   (active, names: '|':UIView:0x1094594c0 )>"
)

然后嘗試通過打破以下約束來解決此問題:

<NSLayoutConstraint:0x10e457fd0 UIImageView:0x10e44e960.height == 1.2*UIImageView:0x10e44e960.width   (active)>

由於我的XIB沒有顯示任何錯誤,我很難確定到底是什么在沖突。

您具有將圖像的高寬比設置為1.2的約束,因此圖像的高度必須為寬度尺寸的1.2倍。

但是,您也將圖像限制為與其父視圖相同的大小,減去某些控件的固定空間。 依次將此視圖設置為與其父視圖相同的大小,減去5個單位的邊框,並且該第三視圖與最外面的視圖具有相同的大小,后者的固定大小為414 x 531。

我希望,一旦解決了所有問題,就無法將圖像制作得比寬高1.2倍。

我會嘗試將圖像的水平約束刪除到其父視圖邊緣,並添加一個新的約束以將其水平居中,然后看看如何進行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM