【发布时间】:2017-04-22 20:24:12
【问题描述】:
使用 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)>
【问题讨论】:
标签: ios swift constraints nslayoutconstraint