Skip to content

Commit dd109b6

Browse files
committed
Fix "cell is slipping away under finger"-bug by rounding distance to the an integer.
Setting a non-integral value to `self.collectionView.contentOffset` will get rounded automatically anyway but `self.currentViewCenter` and `self.currentView.center` won't and that's where the values slowly diverge if the speed is not dividable without rest by 60 (the default fps). The default speed is 300 but bumping it up to e.g. 500 for faster scrolling caused the bug to happen.
1 parent f3033c1 commit dd109b6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ - (void)handleScroll:(CADisplayLink *)displayLink {
213213
CGSize frameSize = self.collectionView.bounds.size;
214214
CGSize contentSize = self.collectionView.contentSize;
215215
CGPoint contentOffset = self.collectionView.contentOffset;
216-
CGFloat distance = self.scrollingSpeed / LX_FRAMES_PER_SECOND;
216+
// Important to have an integer `distance` as the `contentOffset` property automatically gets rounded
217+
// and it would diverge from the view's center resulting in a "cell is slipping away under finger"-bug.
218+
CGFloat distance = rint(self.scrollingSpeed / LX_FRAMES_PER_SECOND);
217219
CGPoint translation = CGPointZero;
218220

219221
switch(direction) {

0 commit comments

Comments
 (0)