Ios UICollectionViewCell自动布局
我在我的故事板中制作了一个简单的自定义Ios UICollectionViewCell自动布局,ios,objective-c,xcode,autolayout,uicollectionviewcell,Ios,Objective C,Xcode,Autolayout,Uicollectionviewcell,我在我的故事板中制作了一个简单的自定义UICollectionViewCell,我也通过编程实现了这一点,并获得了相同的结果 它有一个单数的ui图像视图和两个ui标签,如下所示: <--UIIMAGEVIEW--> <--UILABEL--------> |-(10px)- | | -(10px)- -(10px)-| <----------
UICollectionViewCell
,我也通过编程实现了这一点,并获得了相同的结果
它有一个单数的ui图像视图
和两个ui标签
,如下所示:
<--UIIMAGEVIEW--> <--UILABEL-------->
|-(10px)- | | -(10px)- -(10px)-|
<---------------> <--UILABEL-------->
有什么线索吗?这似乎太不合逻辑了
以下是控制台错误代码:
2014-10-25 18:28:14.273 Air Plan[1579:580797] 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:0x17009edc0 H:[UIImageView:0x1701f7d00(44)]>",
"<NSLayoutConstraint:0x17009f130 H:|-(10)-[UIImageView:0x1701f7d00] (Names: '|':UIView:0x170183810 )>",
"<NSLayoutConstraint:0x17009f270 H:[UIImageView:0x1701f7d00]-(10)-[UILabel:0x155e59970'detailLbl']>",
"<NSLayoutConstraint:0x17009f310 H:[UILabel:0x155e59970'detailLbl']-(10)-| (Names: '|':UIView:0x170183810 )>",
"<NSAutoresizingMaskLayoutConstraint:0x17409eff0 h=--& v=--& H:[UIView:0x170183810(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17009edc0 H:[UIImageView:0x1701f7d00(44)]>
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.
2014-10-25 18:28:14.276 Air Plan[1579:580797] 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:0x17009fcc0 H:[UIImageView:0x1701fa800(44)]>",
"<NSLayoutConstraint:0x17009ff40 H:|-(10)-[UIImageView:0x1701fa800] (Names: '|':UIView:0x170180a90 )>",
"<NSLayoutConstraint:0x1702800a0 H:[UIImageView:0x1701fa800]-(10)-[UILabel:0x155e5b440'detailLbl']>",
"<NSLayoutConstraint:0x170280140 H:[UILabel:0x155e5b440'detailLbl']-(10)-| (Names: '|':UIView:0x170180a90 )>",
"<NSAutoresizingMaskLayoutConstraint:0x17409ea00 h=--& v=--& H:[UIView:0x170180a90(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17009fcc0 H:[UIImageView:0x1701fa800(44)]>
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.
2014-10-25 18:28:14.278 Air Plan[1579:580797] 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:0x170280a00 H:[UIImageView:0x1701fab00(44)]>",
"<NSLayoutConstraint:0x170280c80 H:|-(10)-[UIImageView:0x1701fab00] (Names: '|':UIView:0x1701822f0 )>",
"<NSLayoutConstraint:0x170280dc0 H:[UIImageView:0x1701fab00]-(10)-[UILabel:0x155e5cd10'detailLbl']>",
"<NSLayoutConstraint:0x170280e60 H:[UILabel:0x155e5cd10'detailLbl']-(10)-| (Names: '|':UIView:0x1701822f0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x17409f180 h=--& v=--& H:[UIView:0x1701822f0(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170280a00 H:[UIImageView:0x1701fab00(44)]>
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.
2014-10-25 18:28:14.280 Air Plan[1579:580797] 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:0x170281090 H:[UIImageView:0x1701fae00(44)]>",
"<NSLayoutConstraint:0x170281310 H:|-(10)-[UIImageView:0x1701fae00] (Names: '|':UIView:0x170182220 )>",
"<NSLayoutConstraint:0x1702813b0 H:[UIImageView:0x1701fae00]-(10)-[UILabel:0x155e5d620'titleLbl']>",
"<NSLayoutConstraint:0x170281400 H:[UILabel:0x155e5d620'titleLbl']-(10)-| (Names: '|':UIView:0x170182220 )>",
"<NSAutoresizingMaskLayoutConstraint:0x17409fd60 h=--& v=--& H:[UIView:0x170182220(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170281090 H:[UIImageView:0x1701fae00(44)]>
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.
2014-10-25 18:28:14.282 Air Plan[1579:580797] 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:0x170281b80 H:[UIImageView:0x1701fb100(44)]>",
"<NSLayoutConstraint:0x17409f4a0 H:|-(10)-[UIImageView:0x1701fb100] (Names: '|':UIView:0x170182150 )>",
"<NSLayoutConstraint:0x17409f5e0 H:[UIImageView:0x1701fb100]-(10)-[UILabel:0x155d64210'detailLbl']>",
"<NSLayoutConstraint:0x17409f680 H:[UILabel:0x155d64210'detailLbl']-(10)-| (Names: '|':UIView:0x170182150 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1742800f0 h=--& v=--& H:[UIView:0x170182150(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170281b80 H:[UIImageView:0x1701fb100(44)]>
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.
2014-10-25 18:28:14.273空中计划[1579:580797]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2014-10-25 18:28:14.276空中计划[1579:580797]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2014-10-25 18:28:14.278空中计划[1579:580797]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2014-10-25 18:28:14.280空中计划[1579:580797]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2014-10-25 18:28:14.282空中计划[1579:580797]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
我也遇到了这个问题,并通过在UICollectionViewCell子类中添加以下内容来修复它:
SWIFT>=4.2
override func awakeFromNib() {
contentView.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
}
SWIFT 3
override func awakeFromNib() {
contentView.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
}
OBJC
- (void)awakeFromNib{
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
Xcode 6.1 iOS 8.0.2、8.1
您还可以检查以下答案:创建后单元格和单元格的内容视图的大小为50x50(与集合布局设置的大小无关) 单元格大小正确后,自动布局第一次起作用,但内容视图仍为50x50。可能是iOS 8的问题。其他布局使用正确的内容视图大小。很好,您看到了正确的布局,但日志输出杂乱无章 只需将awakeFromNib中大于最小单元格大小的任何帧设置为iOS 8的内容视图 就你而言
|-(10px)-UIImageView(44px)-(10px)-UILabel-(10px)-|
最小单元格宽度为74-所有显式常量之和
- (void)awakeFromNib {
[super awakeFromNib];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.) {
self.contentView.frame = CGRectMake(0, 0, 200, 100);
}
}
有相同的问题,但设置auoresizingMask不起作用。
设置框架解决了这个问题 我也有这个问题。添加:
[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
破坏了我的视图布局。在我的例子中,我不得不调整一些布局约束,以使视图恢复到我想要的方式。在一种情况下,图像没有垂直居中,因为单元格的高度约束不足。(在这里,我向单元格中最低的元素添加了底部约束)。在另一种情况下,另一个图像(在不同的单元格中)没有居中,我必须进行不同的约束更改。我在该图像上添加了高度约束,并删除了顶部约束,从而解决了问题
我也有问题
[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];