解决方法 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
问题现象:运行时控制台打印错误日志
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'****标题****']-(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) **
(
其实在涉及到UICollectionView自定义layout布局的时候,设置上面的属性=NO,治标不治本,解决不了实际问题.需要重写三个方法
prepareLayout 准备布局方法
//这里可以创建数组或者字典计算每一个cell的frame存储起来
(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect 相交范围内的cell的布局数组
(CGSize)collectionViewContentSize 整个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.
警告:一次只检测到的情况下,约束隐约表明集合视图单元格的内容视图的大小为零。我们正在考虑崩溃无意和使用标准的大小,而不是。
如果你看到nsautoresizingmasklayoutconstraints,你不明白,请参阅文档属性translatesautoresizingmaskintoconstraints UIView
将试图通过打破约束恢复
做一个象征性的断点在uiviewalertforunsatisfiableconstraints抓住在调试器。
在uiconstraintbasedlayoutdebugging类UIView在<< UIKit / UIView上市的方法可能也有帮助。”。
默认情况下,视图的自动调整尺寸面具产生约束,完全确定
视图位置。这允许自动布局系统跟踪的视图的框架,其
布局是手动控制(通过setframe:,例如)。
当您选择放置视图时,通过添加您自己的约束来使用自动布局,
你必须将此属性设置为第IB将为你做这个。