// // custlayout.swift // wallpaper_project import Foundation import UIKit //class CustomLayout: UICollectionViewLayout { // private var cache: [UICollectionViewLayoutAttributes] = [] // private var contentHeight: CGFloat = 0 // // override var collectionViewContentSize: CGSize { // return CGSize(width: collectionView?.bounds.width ?? 0, height: contentHeight) // } // // override func prepare() { // guard let collectionView = collectionView else { return } // cache.removeAll() // // let width = collectionView.bounds.width // var yOffset: CGFloat = 0 // // for item in 0.. [UICollectionViewLayoutAttributes]? { // return cache.filter { $0.frame.intersects(rect) } // } // // override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { // return cache[indexPath.item] // } //} class CustomLayout: UICollectionViewLayout { private var cache: [UICollectionViewLayoutAttributes] = [] private var contentHeight: CGFloat = 0 override var collectionViewContentSize: CGSize { return CGSize(width: collectionView?.bounds.width ?? 0, height: contentHeight) } override func prepare() { guard let collectionView = collectionView else { return } cache.removeAll() let width = collectionView.bounds.width var yOffset: CGFloat = 0 for item in 0.. [UICollectionViewLayoutAttributes]? { return cache.filter { $0.frame.intersects(rect) } } override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { return cache[indexPath.item] } }