Я пытаюсь создать что-то вроде макета App Store на iPad
![enter image description here](https://i.stack.imgur.com/beaUn.jpg)
1 ячейка - 2/3, а следующая ячейка - 1 /3. Тогда следующий ряд будет 1/3 и 2/3 и т. Д.
Я нашел старый пост, в котором говорится об этом , и рекомендовал использовать
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if UIDevice.current.userInterfaceIdiom == .phone {
return CGSize(width: collectionView.bounds.width, height: 80)
} else {
// Number of Items per Row
let numberOfItemsInRow = 2
// Current Row Number
let rowNumber = indexPath.item / numberOfItemsInRow
// Compressed With
let compressedWidth = collectionView.bounds.width / 3
// Expanded Width
let expandedWidth = (collectionView.bounds.width / 3) * 2
// Is Even Row
let isEvenRow = rowNumber % 2 == 0
// Is First Item in Row
let isFirstItem = indexPath.item % numberOfItemsInRow != 0
// Calculate Width
var width: CGFloat = 0.0
if isEvenRow {
width = isFirstItem ? compressedWidth : expandedWidth
} else {
width = isFirstItem ? expandedWidth : compressedWidth
}
return CGSize(width: width, height: 80)
}
}
Однако, когда я реализую этот макет, я получаю:
![enter image description here](https://i.stack.imgur.com/bgovI.png)
Я не уверен, как я могу реализовать этот макет.