Avatar
Kishikawa Katsumi 12/2/2022 10:08 PM
2つのColumnの両方に同じframe.yの値を入れてしまっているので揃ってしまうのではないでしょうか。 override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { let attributes = super.layoutAttributesForElements(in: rect)? .map { $0.copy() } as? [UICollectionViewLayoutAttributes] var offsetYLeft = spacing var offsetYRight = spacing if let attributes { for attribute in attributes { if attribute.indexPath.item % 2 == 0 { attribute.frame.origin.y = offsetYLeft offsetYLeft += attribute.frame.height + spacing } else { attribute.frame.origin.y = offsetYRight offsetYRight += attribute.frame.height + spacing } } } return attributes } ^ こんな感じで左の列と右の列でframe.yの値を別々に計算して設定していけばできると思います。 (edited)
10:15 PM
^ は実際には見えてる部分しかoffsetYを足してないのでスクロールしてもoffsetYを保持して足していけるようにindexPathをキーにしたDictionaryなどで管理する必要があると思います。