在Auto Layout
的帮助下,我以编程方式实现了视图,以处理iPhone 4,5和6的不同设计布局。该程序在除UITableView
之外的所有视图中都很有效。我在控制台中遇到了以下限制问题。
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:0x178be740 V:|-(0)-[UILabel:0x165413b0] (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
"<NSLayoutConstraint:0x178b5910 V:[UILabel:0x165413b0(40)]>",
"<NSLayoutConstraint:0x178a0ac0 V:[UILabel:0x165413b0]-(NSSpace(8))-[UIView:0x1789e5d0]>",
"<NSLayoutConstraint:0x178a0af0 V:[UIView:0x1789e5d0(1)]>",
"<NSLayoutConstraint:0x178a0b20 V:[UIView:0x1789e5d0]-(0)-| (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
"<NSLayoutConstraint:0x178ab4f0 V:|-(10.5)-[UIImageView:0x1789e4c0] (Names: '|':UITableViewCellContentView:0x16541ac0 )>",
"<NSLayoutConstraint:0x178b9ca0 V:[UIImageView:0x1789e4c0(19)]>",
"<NSLayoutConstraint:0x178b9cd0 V:[UIImageView:0x1789e4c0]-(10.5)-| (Names: '|':UITableViewCellContentView:0x16541ac0 )>"
)
我尝试了几个帖子,但未能摆脱限制。可以有人建议吗?
更新了代码
//MyCustomeListCell.h
UILabel *listTitle;
UIImageView *listImage;
UIView *listSplitter;
//MyCustomListCell.m
NSDictionary *viewsDictionary =@{@"listTitle": self.listTitle,@"listImage" : self.listImage,@"listSplitter": self.listSplitter};
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[listTitle(40)]-[listSplitter(1)]|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[listSplitter]|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10.5-[listImage(19)]-10.5-|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-15-[listTitle]-15-[listImage(13)]-20-|" options:0 metrics:nil views:viewsDictionary]];
答案 0 :(得分:1)
此格式字符串,&#34; V:| -10.5- [listImage(19)] - 10.5- |&#34;是说你希望imageView与其超视图的顶部和底部分开10.5点,但也要高19点。因此,除非superview在所有屏幕尺寸中都高出40个点,否则会导致错误。
与此相同,&#34; V:| [listTitle(40)] - [listSplitter(1)] |&#34;只有当超级视图高49点(短跑40 + 8(我认为)+ 1)时,这个才有效。
要解决这些问题,您需要不要让系统受到限制。根据您的需要,您可以删除&#34; |&#34;从这些格式字符串的一端,或摆脱大小设置。
答案 1 :(得分:1)
有更简单的方法,不使用约束,但autoresizingMask
:
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;