From b88d7c2182d90c781e5ef88ce2e7a2d7b4f87342 Mon Sep 17 00:00:00 2001 From: dingwenchao Date: Tue, 9 Feb 2016 15:19:24 +0800 Subject: [PATCH] When invalidating frames, the headerHeight and weekdayHeight shouldn't be invalidated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. When invalidating frames, the headerHeight and weekdayHeight shouldn't be invalidated 2. Fix deprecated grammar 3. When the selectedDate is not in screen, but ‘today’ is, focus on ‘today’. --- FSCalendar/FSCalendar+IBExtension.h | 4 +-- FSCalendar/FSCalendar.m | 5 +--- FSCalendar/FSCalendarAppearance.h | 16 ++++++------ FSCalendar/FSCalendarConstance.h | 4 +-- FSCalendar/FSCalendarFlowLayout.m | 39 ++++++++++++++++++++++++++--- 5 files changed, 49 insertions(+), 19 deletions(-) diff --git a/FSCalendar/FSCalendar+IBExtension.h b/FSCalendar/FSCalendar+IBExtension.h index 5e14f5d..2912530 100644 --- a/FSCalendar/FSCalendar+IBExtension.h +++ b/FSCalendar/FSCalendar+IBExtension.h @@ -53,7 +53,7 @@ IB_DESIGNABLE @property (assign, nonatomic) IBInspectable NSInteger fakedSelectedDay; // Deprecated -@property (assign, nonatomic) FSCalendarCellStyle cellStyle FSCalendarDeprecated("use \'cellShape\' instead"); -@property (assign, nonatomic) BOOL autoAdjustTitleSize FSCalendarDeprecated("use \'adjustsFontSizeToFitContentSize\' instead"); +@property (assign, nonatomic) FSCalendarCellStyle cellStyle FSCalendarDeprecated('cellShape'); +@property (assign, nonatomic) BOOL autoAdjustTitleSize FSCalendarDeprecated('adjustsFontSizeToFitContentSize'); @end diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index 5056976..bba393c 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -137,7 +137,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) { @implementation FSCalendar @dynamic selectedDate; -@synthesize scrollDirection = _scrollDirection, firstWeekday = _firstWeekday, headerHeight = _headerHeight, appearance = _appearance; +@synthesize scrollDirection = _scrollDirection, firstWeekday = _firstWeekday, appearance = _appearance; #pragma mark - Life Cycle && Initialize @@ -1594,9 +1594,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) { _needsAdjustingTextSize = YES; _needsAdjustingMonthPosition = YES; - _headerHeight = FSCalendarAutomaticDimension; - _weekdayHeight = FSCalendarAutomaticDimension; - _preferedHeaderHeight = FSCalendarAutomaticDimension; _preferedWeekdayHeight = FSCalendarAutomaticDimension; _preferedRowHeight = FSCalendarAutomaticDimension; diff --git a/FSCalendar/FSCalendarAppearance.h b/FSCalendar/FSCalendarAppearance.h index 2435ad8..65aac69 100644 --- a/FSCalendar/FSCalendarAppearance.h +++ b/FSCalendar/FSCalendarAppearance.h @@ -84,15 +84,15 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) { @interface FSCalendarAppearance (Deprecated) -@property (assign, nonatomic) FSCalendarCellStyle cellStyle FSCalendarDeprecated("use \'cellShape\' instead"); -@property (assign, nonatomic) BOOL useVeryShortWeekdaySymbols FSCalendarDeprecated("use \'caseOptions\' instead"); -@property (assign, nonatomic) BOOL autoAdjustTitleSize FSCalendarDeprecated("use \'adjustFontSizeToFitCellSize\' instead"); -@property (assign, nonatomic) BOOL adjustsFontSizeToFitCellSize FSCalendarDeprecated("use \'adjustFontSizeToFitContentSize\' instead"); +@property (assign, nonatomic) FSCalendarCellStyle cellStyle FSCalendarDeprecated('cellShape'); +@property (assign, nonatomic) BOOL useVeryShortWeekdaySymbols FSCalendarDeprecated('caseOptions'); +@property (assign, nonatomic) BOOL autoAdjustTitleSize FSCalendarDeprecated('adjustFontSizeToFitContentSize'); +@property (assign, nonatomic) BOOL adjustsFontSizeToFitCellSize FSCalendarDeprecated('adjustFontSizeToFitContentSize'); -@property (assign, nonatomic) CGFloat titleTextSize FSCalendarDeprecated("use \'titleFont\' instead"); -@property (assign, nonatomic) CGFloat subtitleTextSize FSCalendarDeprecated("use \'subtitleFont\' instead"); -@property (assign, nonatomic) CGFloat weekdayTextSize FSCalendarDeprecated("use \'weekdayFont\' instead"); -@property (assign, nonatomic) CGFloat headerTitleTextSize FSCalendarDeprecated("use \'headerTitleFont\' instead"); +@property (assign, nonatomic) CGFloat titleTextSize FSCalendarDeprecated('titleFont'); +@property (assign, nonatomic) CGFloat subtitleTextSize FSCalendarDeprecated('subtitleFont'); +@property (assign, nonatomic) CGFloat weekdayTextSize FSCalendarDeprecated('weekdayFont'); +@property (assign, nonatomic) CGFloat headerTitleTextSize FSCalendarDeprecated('headerTitleFont'); @end diff --git a/FSCalendar/FSCalendarConstance.h b/FSCalendar/FSCalendarConstance.h index e68cc58..2fb366e 100644 --- a/FSCalendar/FSCalendarConstance.h +++ b/FSCalendar/FSCalendarConstance.h @@ -40,13 +40,13 @@ UIKIT_EXTERN NSInteger const FSCalendarDefaultHourComponent; #define FSCalendarDeprecated(instead) __attribute((deprecated(" Use " # instead " instead"))) -FSCalendarDeprecated("use \'FSCalendarCellShape\' instead") +FSCalendarDeprecated('FSCalendarCellShape') typedef NS_ENUM(NSInteger, FSCalendarCellStyle) { FSCalendarCellStyleCircle = 0, FSCalendarCellStyleRectangle = 1 }; -FSCalendarDeprecated("use \'FSCalendarScrollDirection\' instead") +FSCalendarDeprecated('FSCalendarScrollDirection') typedef NS_ENUM(NSInteger, FSCalendarFlow) { FSCalendarFlowVertical, FSCalendarFlowHorizontal diff --git a/FSCalendar/FSCalendarFlowLayout.m b/FSCalendar/FSCalendarFlowLayout.m index 8237a36..707ab83 100644 --- a/FSCalendar/FSCalendarFlowLayout.m +++ b/FSCalendar/FSCalendarFlowLayout.m @@ -116,7 +116,7 @@ NSInteger focusedRowNumber = 0; if (self.calendar.focusOnSingleSelectedDate) { - NSDate *focusedDate = self.calendar.selectedDate ?: self.calendar.today; + NSDate *focusedDate = self.calendar.selectedDate; if (focusedDate) { UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:[self.calendar indexPathForDate:focusedDate scope:FSCalendarScopeMonth]]; CGPoint focuedCenter = attributes.center; @@ -131,6 +131,27 @@ break; } } + } else { + focusedDate = nil; + } + } + if (!focusedDate) { + focusedDate = self.calendar.today; + if (focusedDate) { + UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:[self.calendar indexPathForDate:focusedDate scope:FSCalendarScopeMonth]]; + CGPoint focuedCenter = attributes.center; + if (CGRectContainsPoint(self.collectionView.bounds, focuedCenter)) { + switch (self.scrollDirection) { + case UICollectionViewScrollDirectionHorizontal: { + focusedRowNumber = attributes.indexPath.item%6; + break; + } + case UICollectionViewScrollDirectionVertical: { + focusedRowNumber = attributes.indexPath.item/7; + break; + } + } + } } } } @@ -221,15 +242,27 @@ NSInteger focusedRowNumber = 0; NSDate *currentPage = self.calendar.currentPage; NSDate *firstDayOfMonth = nil; - if (self.calendar.focusOnSingleSelectedDate && self.calendar.selectedDate) { - NSDate *focusedDate = self.calendar.selectedDate ?: self.calendar.today; + if (self.calendar.focusOnSingleSelectedDate) { + NSDate *focusedDate = self.calendar.selectedDate; if (focusedDate) { UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:[self.calendar indexPathForDate:focusedDate scope:FSCalendarScopeWeek]]; CGPoint focuedCenter = attributes.center; if (CGRectContainsPoint(self.collectionView.bounds, focuedCenter)) { firstDayOfMonth = [self.calendar beginingOfMonthOfDate:focusedDate]; + } else { + focusedDate = nil; } } + if (!focusedDate) { + focusedDate = self.calendar.today; + if (focusedDate) { + UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:[self.calendar indexPathForDate:focusedDate scope:FSCalendarScopeWeek]]; + CGPoint focuedCenter = attributes.center; + if (CGRectContainsPoint(self.collectionView.bounds, focuedCenter)) { + firstDayOfMonth = [self.calendar beginingOfMonthOfDate:focusedDate]; + } + } + }; } firstDayOfMonth = firstDayOfMonth ?: [self.calendar beginingOfMonthOfDate:currentPage]; NSInteger weekdayOfFirstDay = [self.calendar weekdayOfDate:firstDayOfMonth];