@@ -35,6 +35,8 @@ open class InfiniteCollectionView: UICollectionView {
3535 fileprivate var indexOffset : Int = 0
3636 fileprivate var contentWidth : CGFloat = UIScreen . main. bounds. width
3737 fileprivate var pageIndex = 0
38+ @available ( * , deprecated, message: " It becomes unnecessary because it uses UICollectionViewFlowLayout. " )
39+ open var cellWidth : CGFloat ?
3840 required public init ? ( coder aDecoder: NSCoder ) {
3941 super. init ( coder: aDecoder)
4042 configure ( )
@@ -52,19 +54,19 @@ open class InfiniteCollectionView: UICollectionView {
5254 }
5355 open func rotate( _ notification: Notification ) {
5456 contentWidth = totalContentWidth
55- contentOffset = CGPoint ( x: CGFloat ( pageIndex + indexOffset) * cellWidth , y: contentOffset. y)
57+ contentOffset = CGPoint ( x: CGFloat ( pageIndex + indexOffset) * itemWidth , y: contentOffset. y)
5658 }
5759}
5860
5961// MARK: - private
6062private extension InfiniteCollectionView {
61- var cellWidth : CGFloat {
63+ var itemWidth : CGFloat {
6264 guard let layout = collectionViewLayout as? UICollectionViewFlowLayout else { return 0 }
6365 return layout. itemSize. width + layout. minimumInteritemSpacing
6466 }
6567 var totalContentWidth : CGFloat {
6668 let numberOfCells : CGFloat = CGFloat ( infiniteDataSource? . number ( ofItems: self ) ?? 0 )
67- return numberOfCells * cellWidth
69+ return numberOfCells * itemWidth
6870 }
6971 func configure( ) {
7072 delegate = self
@@ -77,9 +79,9 @@ private extension InfiniteCollectionView {
7779 let centerX = ( scrollView. contentSize. width - bounds. width) / 2
7880 let distFromCenter = centerX - currentOffset. x
7981 if fabs ( distFromCenter) > ( contentWidth / 4 ) {
80- let cellcount = distFromCenter / cellWidth
82+ let cellcount = distFromCenter / itemWidth
8183 let shiftCells = Int ( ( cellcount > 0 ) ? floor ( cellcount) : ceil ( cellcount) )
82- let offsetCorrection = ( abs ( cellcount) . truncatingRemainder ( dividingBy: 1 ) ) * cellWidth
84+ let offsetCorrection = ( abs ( cellcount) . truncatingRemainder ( dividingBy: 1 ) ) * itemWidth
8385 if centerX > contentOffset. x {
8486 contentOffset = CGPoint ( x: centerX - offsetCorrection, y: currentOffset. y)
8587 } else {
0 commit comments