解決方法 UIView的屬性
self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
/* By default, the autoresizing mask on a view gives rise to constraints that fully determine
the view's position. This allows the auto layout system to track the frames of views whose
layout is controlled manually (through -setFrame:, for example).
When you elect to position the view using auto layout by adding your own constraints,
you must set this property to NO. IB will do this for you.
*/
@property(nonatomic) BOOL translatesAutoresizingMaskIntoConstraints NS_AVAILABLE_IOS(6_0); // Default YES
問(wèn)題現(xiàn)象:運(yùn)行時(shí)控制臺(tái)打印錯(cuò)誤日志
2016-08-23 14:18:33.213 haokanLive[3428:2068691] Warning once only: Detected a case where constraints ambiguously suggest a size of zero for a collection view cell's content view. We're considering the collapse unintentional and using standard size instead.
2016-08-23 14:18:33.219 haokanLive[3428:2068691] yiyang****的****cell的contentView<UIView: 0x14e745a20; frame = (0 0; 375 460); gestureRecognizers = <NSArray: 0x14e55bde0>; layer = <CALayer: 0x14e745250>>
2016-08-23 14:18:35.464 haokanLive[3428:2068691] 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) **
(
** "<NSAutoresizingMaskLayoutConstraint:0x14e554e50 h=--& v=--& H:[UIView:0x14e555180(0)]>",**
** "<NSLayoutConstraint:0x14e547020 H:[UILabel:0x14e5527a0'\U6807\U9898']-(8)-| (Names: '|':UIView:0x14e555180 )>",**
** "<NSLayoutConstraint:0x14e5470c0 H:|-(8)-[UILabel:0x14e5527a0'\U6807\U9898'] (Names: '|':UIView:0x14e555180 )>"**
)
**Will attempt to recover by breaking constraint **
<NSLayoutConstraint:0x14e547020 H:[UILabel:0x14e5527a0'****標(biāo)題****']-(8)-| (Names: '|':UIView:0x14e555180 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-08-23 14:18:35.467 haokanLive[3428:2068691] 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) **
(
其實(shí)在涉及到UICollectionView自定義layout布局的時(shí)候,設(shè)置上面的屬性=NO,治標(biāo)不治本,解決不了實(shí)際問(wèn)題.需要重寫(xiě)三個(gè)方法
prepareLayout 準(zhǔn)備布局方法
//這里可以創(chuàng)建數(shù)組或者字典計(jì)算每一個(gè)cell的frame存儲(chǔ)起來(lái)
(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect 相交范圍內(nèi)的cell的布局?jǐn)?shù)組
(CGSize)collectionViewContentSize 整個(gè)collectionView的contentSize
Warning once only: Detected a case where constraints ambiguously suggest a size of zero for a collection view cell's content view. We're considering the collapse unintentional and using standard size instead.
If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
By default, the autoresizing mask on a view gives rise to constraints that fully determine
the view's position. This allows the auto layout system to track the frames of views whose
layout is controlled manually (through -setFrame:, for example).
When you elect to position the view using auto layout by adding your own constraints,
you must set this property to NO. IB will do this for you.
警告:一次只檢測(cè)到的情況下,約束隱約表明集合視圖單元格的內(nèi)容視圖的大小為零灾常。我們正在考慮崩潰無(wú)意和使用標(biāo)準(zhǔn)的大小嚼吞,而不是闰蛔。
如果你看到nsautoresizingmasklayoutconstraints,你不明白斧蜕,請(qǐng)參閱文檔屬性translatesautoresizingmaskintoconstraints UIView
將試圖通過(guò)打破約束恢復(fù)
做一個(gè)象征性的斷點(diǎn)在uiviewalertforunsatisfiableconstraints抓住在調(diào)試器瓤帚。
在uiconstraintbasedlayoutdebugging類UIView在<< UIKit / UIView上市的方法可能也有幫助嘿架《舛”栅屏。
默認(rèn)情況下,視圖的自動(dòng)調(diào)整尺寸面具產(chǎn)生約束艾扮,完全確定
視圖位置既琴。這允許自動(dòng)布局系統(tǒng)跟蹤的視圖的框架,其
布局是手動(dòng)控制(通過(guò)setframe:泡嘴,例如)。
當(dāng)您選擇放置視圖時(shí)逆济,通過(guò)添加您自己的約束來(lái)使用自動(dòng)布局酌予,
你必須將此屬性設(shè)置為第IB將為你做這個(gè)。