使用CollectionViewCells创建“卡片式”菜单,我需要在任何屏幕大小下,让这些单元格之间的间距相同,就像|------|一样。我已经实现了以下效果:
但我收到了这个日志:
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-15-[v0]-15-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": appsCollectionView]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": appsCollectionView]))
我已将屏幕两侧的边距设置为15,但每当我在更大的屏幕上加载应用时,间隔的空间也会改变。
我尝试使用以下方法:
appsCollectionView.leadingAnchor.constraint(equalTo: trailingAnchor).isActive = true
但我收到了这个日志:
2016-12-07 16:51:14.902586 AppStoreClone[8843:206635] [LayoutConstraints] 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.
(
"<NSLayoutConstraint:0x608000283fc0 H:[UICollectionView:0x7f8172010200]-(15)-| (active, names: '|':AppStoreClone.CategoryCell:0x7f8173309710 )>",
"<NSLayoutConstraint:0x608000284100 H:[AppStoreClone.CategoryCell:0x7f8173309710]-(0)-[UICollectionView:0x7f8172010200] (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000284100 H:[AppStoreClone.CategoryCell:0x7f8173309710]-(0)-[UICollectionView:0x7f8172010200] (active)>