2016-12-07 1 views
3

Создание меню «Card-style» с помощью CollectionViewCells, и мне нужны ячейки, имеющие одинаковое пространство между | ------ | в любом размере экрана.Добавить Constraints программно в ViewControllerCells

я был в состоянии добраться до этой точки:

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 

Но я получаю этот LOG:

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)> 

ответ