From 92b665e6febb6ab89874eaf915401f4bfea07370 Mon Sep 17 00:00:00 2001 From: DingWenchao Date: Fri, 26 Jun 2015 08:57:00 +0800 Subject: [PATCH] Update event handling Update event handling --- Pod/Classes/FSCalendar.m | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Pod/Classes/FSCalendar.m b/Pod/Classes/FSCalendar.m index 9ac8bee..06b5807 100644 --- a/Pod/Classes/FSCalendar.m +++ b/Pod/Classes/FSCalendar.m @@ -308,14 +308,19 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { - if (_supressEvent) { + if (!_minimumDate) { return; } CGFloat scrollOffset = MAX(scrollView.contentOffset.x/scrollView.fs_width, scrollView.contentOffset.y/scrollView.fs_height); NSDate *currentMonth = [_minimumDate fs_dateByAddingMonths:round(scrollOffset)]; + + BOOL monthChanged = NO; if (![_currentMonth fs_isEqualToDateForMonth:currentMonth]) { _currentMonth = [currentMonth copy]; + monthChanged = YES; + } + if (monthChanged && !_supressEvent) { [self currentMonthDidChange]; } _header.scrollOffset = scrollOffset; @@ -337,12 +342,10 @@ _supressEvent = YES; NSDate *currentMonth = self.currentMonth; _collectionViewFlowLayout.scrollDirection = (UICollectionViewScrollDirection)flow; - [self setNeedsLayout]; - dispatch_async(dispatch_get_main_queue(), ^{ - [self reloadData]; - [self scrollToDate:currentMonth]; - _supressEvent = NO; - }); + [self layoutSubviews]; + [self reloadData]; + [self scrollToDate:currentMonth]; + _supressEvent = NO; } }