Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling so fast does not trigger calendarCurrentPageDidChange #113

Closed
IsmailHassanein opened this issue Oct 8, 2015 · 4 comments
Closed

Comments

@IsmailHassanein
Copy link

Hi @WenchaoIOS
I have a probelm. when I scroll very fast in Horizontal direction calendarCurrentPageDidChange delegate method sometimes not called.
To reperduce this bug:
open SwiftExample and just change the scrollingDirection to Horizontal.
calendar.scrollDirection = .Horizontal
start scrolling as fast as you can serveral time and watch the debug area to see the messages printed calendarCurrentPageDidChange
Thanks.

@WenchaoD
Copy link
Owner

WenchaoD commented Oct 8, 2015

I C ...
scrollViewWillEndDragging: delegate method will not get triggered when you scroll really fast. Seems to be a problem of UIScrollView. Have any suggestion?

@IsmailHassanein
Copy link
Author

@WenchaoIOS After doing some tests. I found that scrollViewDidEndDecelerating is always called after the scrollView stops scrolling.

You may check recalculate the current page using the contentOffset and it is not updated. update it and call the delegate method. Something like below:

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (!_pagingEnabled) {
        return;
    }
     CGFloat currentOffset = 0, contentSize = 0;
    switch (_collectionViewLayout.scrollDirection) {
        case UICollectionViewScrollDirectionHorizontal: {
            currentOffset = scrollView.contentOffset.x;
            contentSize = scrollView.fs_width;
            break;
        }
        case UICollectionViewScrollDirectionVertical: {
            currentOffset = scrollView.contentOffset.y;
            contentSize = scrollView.fs_height;
            break;
        }
        default: {
            break;
        }
    }
    if (_minimumDate) {
        NSDate *newPage;
        switch (_scope) {
            case FSCalendarScopeMonth: {
                newPage = [_minimumDate fs_dateByAddingMonths:currentOffset/contentSize].fs_dateByIgnoringTimeComponents.fs_firstDayOfMonth;
                break;
            }
            case FSCalendarScopeWeek: {
                newPage = [_minimumDate fs_dateByAddingWeeks:currentOffset/contentSize].fs_dateByIgnoringTimeComponents.fs_firstDayOfWeek;
                break;
            }
            default: {
                break;
            }
        }
        if (![_currentPage fs_isEqualToDateForDay: newPage]) {
            [self willChangeValueForKey:@"currentPage"];
            _currentPage = newPage;
            [self currentPageDidChange];
            [self didChangeValueForKey:@"currentPage"];
        }
    }
}

I hope this help.

@WenchaoD
Copy link
Owner

WenchaoD commented Oct 9, 2015

Got it. I'll take this into consideration.

WenchaoD added a commit that referenced this issue May 29, 2016
Fix problem #113
@WenchaoD
Copy link
Owner

Should've been fixed. Sorry for being late as there's no solution from Google.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants