Update event handling

Update event handling
This commit is contained in:
DingWenchao 2015-06-26 08:57:00 +08:00
parent 1002377b43
commit 92b665e6fe
1 changed files with 10 additions and 7 deletions

View File

@ -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;
}
}