単一のセルだけが返された場合は、UICollectionviewセルの中央揃えが必要です。私はこれを使用しています中央の単一のコレクションビューセルの整列
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if self.imageSelected.count == 1
{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsetsMake(0, 100, 0, 0)
}
}
return self.imageSelected.count
}
上記のコードは、カウントが1の場合に選択されていますが、セルの位置に動きがないと表示されています。
私もこれを試してみましたが、ここでそれもブレークポイント
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
if self.imageSelected.count == 1 {
return UIEdgeInsetsMake(0, 100, 0, 0)
} else {
return UIEdgeInsetsMake(0, 0, 0, 0)
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.imageSelected.count
}
これはカスタムコレクションビューのレイアウトです。 – TheCodingArt