From df0ded5ffd5fcc36553cb05dc17a10b1e8e41eab Mon Sep 17 00:00:00 2001 From: yyjim Date: Thu, 10 Nov 2022 08:56:35 +0800 Subject: [PATCH] fix: fix jerk effect https://github.com/zepojo/UPCarouselFlowLayout/issues/37 --- UPCarouselFlowLayout/UPCarouselFlowLayout.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/UPCarouselFlowLayout/UPCarouselFlowLayout.swift b/UPCarouselFlowLayout/UPCarouselFlowLayout.swift index a4a5da1..61e7864 100644 --- a/UPCarouselFlowLayout/UPCarouselFlowLayout.swift +++ b/UPCarouselFlowLayout/UPCarouselFlowLayout.swift @@ -120,8 +120,9 @@ open class UPCarouselFlowLayout: UICollectionViewFlowLayout { let isHorizontal = (self.scrollDirection == .horizontal) let midSide = (isHorizontal ? collectionView.bounds.size.width : collectionView.bounds.size.height) / 2 - let proposedContentOffsetCenterOrigin = (isHorizontal ? proposedContentOffset.x : proposedContentOffset.y) + midSide - + let proposedContentOffsetCenterOrigin = (isHorizontal ? proposedContentOffset.x + 1000 * velocity.x : proposedContentOffset.y + 1000 * velocity.y) + midSide + + var targetContentOffset: CGPoint if isHorizontal { let closest = layoutAttributes.sorted { abs($0.center.x - proposedContentOffsetCenterOrigin) < abs($1.center.x - proposedContentOffsetCenterOrigin) }.first ?? UICollectionViewLayoutAttributes()