簡體   English   中英

AutoLayout例外iOS6

[英]AutoLayout exceptions iOS6

我目前正在使用帶有自動布局的xib在集合視圖中創建自定義單元格。 兩種方向的單元格大小都不同。 因此,我根據方向更改了單元的寬度和高度。

問題是,當我更改設備方向時,在iOS6中會收到大量警告/異常。

但是,當我在iOS7中執行相同操作時,沒有警告出現。

盡管它不會影響我的功能,但我想刪除所有這些警告。

這是我的XIB文件

以下是我得到的錯誤/警告/例外。

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:0x164371f0 V:[UILabel:0x16437240(21)]>",
"<NSLayoutConstraint:0x16438050 V:[UILabel:0x16437240]-(1)-[UILabel:0x16437670]>",
"<NSLayoutConstraint:0x16437fd0 V:[UILabel:0x16437670]-(5)-|   (Names: '|':LibraryCollectionViewCell:0x16436ae0 )>",
"<NSLayoutConstraint:0x16437f50 V:[UILabel:0x16436e10]-(0)-[UILabel:0x16437240]>",
"<NSLayoutConstraint:0x16437e90 V:|-(7)-[UILabel:0x16436e10]   (Names: '|':LibraryCollectionViewCell:0x16436ae0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x16354d00 h=--& v=--& V:[UICollectionView:0xb24f200(264)]>",
"<NSAutoresizingMaskLayoutConstraint:0x163513b0 h=-&- v=-&- LibraryCollectionViewCell:0x16436ae0.height == UICollectionView:0xb24f200.height - 264>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x164371f0 V:[UILabel:0x16437240(21)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

我已經嘗試過[cell setTranslatesAutoresizingMaskIntoConstraints:NO]但是它使應用程序崩潰了。

有人可以為此提供一些解決方案嗎?

"<NSLayoutConstraint:0x164371f0 V:[UILabel:0x16437240(21)]>",
"<NSLayoutConstraint:0x16438050 V:[UILabel:0x16437240]-(1)-[UILabel:0x16437670]>",
"<NSLayoutConstraint:0x16437fd0 V:[UILabel:0x16437670]-(5)-|   (Names: '|':LibraryCollectionViewCell:0x16436ae0 )>",
"<NSLayoutConstraint:0x16437f50 V:[UILabel:0x16436e10]-(0)-[UILabel:0x16437240]>",
"<NSLayoutConstraint:0x16437e90 V:|-(7)-[UILabel:0x16436e10]   (Names: '|':LibraryCollectionViewCell:0x16436ae0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x16354d00 h=--& v=--& V:[UICollectionView:0xb24f200(264)]>",
"<NSAutoresizingMaskLayoutConstraint:0x163513b0 h=-&- v=-&- LibraryCollectionViewCell:0x16436ae0.height == UICollectionView:0xb24f200.height - 264>"

好的,不受您的限制,您有...

(括號中的數字是參考的最后3位數字)。

Label (240) with height constraint fixed to 21.
Label (240) with a vertical gap of 1 to label (670).
Label (670) with a vertical gap of 5 to the superview (ae0) bottom.
Label (e10) with a vertical gap of 7 to the superview (ae0) top.

UICollectionView (200) with fixed height of 264.
LibraryCollectionViewCell (ae0) with an equal height to the collection view - 264 (200).

<Adam Savage>好! 有您的問題!</ Adam Savage>

列表中的最后一個約束將使單元格的高度為0。(264-264 = 0)。但是,在單元格中,標簽的高度固定為21,垂直間距為7、5和1。

264 - 264 = 0
21 + 7 + 5 + 1 = 36

36 != 0

您可以通過多種方法解決此問題。 刪除單元格和集合視圖之間的約束。 移除標簽上的固定高度限制。 等等...

我建議(在紙上)勾勒出您希望它如何工作,並在需要的約束中進行細化。 或在問題中附上您想做什么的圖片,以便我們提供幫助。

iOS 6.0iOS 7.0 Auto layout方式發生了很多變化。

從通過X-Code 4.xX-Code 5.x自動布局實現中可以明顯看出這一點。

由於Apple現在期望應用程序將使用X-Code 5.x構建,因此我建議使用相同的代碼。

還要檢查base SDK

暫無
暫無

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

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