@@ -213,6 +213,7 @@ - (void)handleScroll:(CADisplayLink *)displayLink {
213213 CGSize frameSize = self.collectionView .bounds .size ;
214214 CGSize contentSize = self.collectionView .contentSize ;
215215 CGPoint contentOffset = self.collectionView .contentOffset ;
216+ UIEdgeInsets contentInset = self.collectionView .contentInset ;
216217 // Important to have an integer `distance` as the `contentOffset` property automatically gets rounded
217218 // and it would diverge from the view's center resulting in a "cell is slipping away under finger"-bug.
218219 CGFloat distance = rint (self.scrollingSpeed / LX_FRAMES_PER_SECOND);
@@ -221,16 +222,16 @@ - (void)handleScroll:(CADisplayLink *)displayLink {
221222 switch (direction) {
222223 case LXScrollingDirectionUp: {
223224 distance = -distance;
224- CGFloat minY = 0 .0f ;
225+ CGFloat minY = 0 .0f - contentInset. top ;
225226
226227 if ((contentOffset.y + distance) <= minY) {
227- distance = -contentOffset.y ;
228+ distance = -contentOffset.y - contentInset. top ;
228229 }
229230
230231 translation = CGPointMake (0 .0f , distance);
231232 } break ;
232233 case LXScrollingDirectionDown: {
233- CGFloat maxY = MAX (contentSize.height , frameSize.height ) - frameSize.height ;
234+ CGFloat maxY = MAX (contentSize.height , frameSize.height ) - frameSize.height + contentInset. bottom ;
234235
235236 if ((contentOffset.y + distance) >= maxY) {
236237 distance = maxY - contentOffset.y ;
@@ -240,16 +241,16 @@ - (void)handleScroll:(CADisplayLink *)displayLink {
240241 } break ;
241242 case LXScrollingDirectionLeft: {
242243 distance = -distance;
243- CGFloat minX = 0 .0f ;
244+ CGFloat minX = 0 .0f - contentInset. left ;
244245
245246 if ((contentOffset.x + distance) <= minX) {
246- distance = -contentOffset.x ;
247+ distance = -contentOffset.x - contentInset. left ;
247248 }
248249
249250 translation = CGPointMake (distance, 0 .0f );
250251 } break ;
251252 case LXScrollingDirectionRight: {
252- CGFloat maxX = MAX (contentSize.width , frameSize.width ) - frameSize.width ;
253+ CGFloat maxX = MAX (contentSize.width , frameSize.width ) - frameSize.width + contentInset. right ;
253254
254255 if ((contentOffset.x + distance) >= maxX) {
255256 distance = maxX - contentOffset.x ;
0 commit comments