When invalidating frames, the headerHeight and weekdayHeight shouldn't be invalidated

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’.
This commit is contained in:
dingwenchao 2016-02-09 15:19:24 +08:00
parent eecea2e0b8
commit b88d7c2182
5 changed files with 49 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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