diff --git a/Example/FSCalendarScopeExampleViewController.m b/Example/FSCalendarScopeExampleViewController.m index 4f90f18f..de43cda6 100644 --- a/Example/FSCalendarScopeExampleViewController.m +++ b/Example/FSCalendarScopeExampleViewController.m @@ -16,6 +16,9 @@ - (void)viewDidLoad { [super viewDidLoad]; [_calendar selectDate:[NSDate date]]; + + // Uncomment this to perform an 'initial-week-scope' +// _calendar.scope = FSCalendarScopeWeek; } - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated diff --git a/Example/ScopeHandleViewController.m b/Example/ScopeHandleViewController.m index e26012fb..fb651bf6 100644 --- a/Example/ScopeHandleViewController.m +++ b/Example/ScopeHandleViewController.m @@ -45,6 +45,9 @@ - (void)viewDidLoad [super viewDidLoad]; [self.calendar selectDate:[self.calendar dateFromString:@"2016-05-10" format:@"yyyy-MM-dd"]]; + + // Uncomment this to perform an 'initial-week-scope' + // self.calendar.scope = FSCalendarScopeWeek; } - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index 7ec00381..38dce590 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -316,7 +316,7 @@ - (void)layoutSubviews CGFloat headerHeight = self.preferredHeaderHeight; CGFloat weekdayHeight = self.preferredWeekdayHeight; CGFloat rowHeight = self.preferredRowHeight; - CGFloat weekdayWidth = self.contentView.fs_width/_weekdays.count; + CGFloat weekdayWidth = self.fs_width/_weekdays.count; CGFloat padding = weekdayHeight*0.1; if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal) { padding = FSCalendarFloor(padding); @@ -364,6 +364,7 @@ - (void)layoutSubviews } _topBorder.frame = CGRectMake(0, -1, self.fs_width, 1); _bottomBorder.frame = CGRectMake(0, self.fs_height, self.fs_width, 1); + _scopeHandle.fs_bottom = _bottomBorder.fs_top; } if (_needsAdjustingTextSize) { @@ -395,12 +396,12 @@ - (void)layoutSublayersOfLayer:(CALayer *)layer [super layoutSublayersOfLayer:layer]; if (layer == self.layer) { if (_needsAdjustingViewFrame) { - _needsAdjustingViewFrame = NO; - CGSize size = [self sizeThatFits:self.frame.size]; _maskLayer.frame = self.bounds; _maskLayer.path = [UIBezierPath bezierPathWithRect:(CGRect){CGPointZero,size}].CGPath; - + dispatch_async(dispatch_get_main_queue(), ^{ + _needsAdjustingViewFrame = NO; + }); } } } @@ -973,8 +974,9 @@ - (CGFloat)preferredHeaderHeight if (_headerHeight == FSCalendarAutomaticDimension) { if (_preferredWeekdayHeight == FSCalendarAutomaticDimension) { if (!self.floatingMode) { - CGFloat divider = _scope == FSCalendarScopeMonth ? FSCalendarStandardMonthlyPageHeight : FSCalendarStandardWeeklyPageHeight; - _preferredHeaderHeight = (FSCalendarStandardHeaderHeight/divider)*_contentView.fs_height; + CGFloat divider = FSCalendarStandardMonthlyPageHeight; + CGFloat contentHeight = self.animator.cachedMonthSize.height*(1-_showsScopeHandle*0.075); + _preferredHeaderHeight = (FSCalendarStandardHeaderHeight/divider)*contentHeight; _preferredHeaderHeight -= (_preferredHeaderHeight-FSCalendarStandardHeaderHeight)*0.5; } else { _preferredHeaderHeight = FSCalendarStandardHeaderHeight*MAX(1, FSCalendarDeviceIsIPad*1.5)*_lineHeightMultiplier; @@ -990,8 +992,9 @@ - (CGFloat)preferredWeekdayHeight if (_weekdayHeight == FSCalendarAutomaticDimension) { if (_preferredWeekdayHeight == FSCalendarAutomaticDimension) { if (!self.floatingMode) { - CGFloat divider = _scope == FSCalendarScopeMonth ? FSCalendarStandardMonthlyPageHeight : FSCalendarStandardWeeklyPageHeight; - _preferredWeekdayHeight = (FSCalendarStandardWeekdayHeight/divider)*_contentView.fs_height; + CGFloat divider = FSCalendarStandardMonthlyPageHeight; + CGFloat contentHeight = self.animator.cachedMonthSize.height*(1-_showsScopeHandle*0.075); + _preferredWeekdayHeight = (FSCalendarStandardWeekdayHeight/divider)*contentHeight; } else { _preferredWeekdayHeight = FSCalendarStandardWeekdayHeight*MAX(1, FSCalendarDeviceIsIPad*1.5)*_lineHeightMultiplier; } @@ -1006,22 +1009,13 @@ - (CGFloat)preferredRowHeight if (_preferredRowHeight == FSCalendarAutomaticDimension) { CGFloat headerHeight = self.preferredHeaderHeight; CGFloat weekdayHeight = self.preferredWeekdayHeight; - CGFloat contentHeight = self.contentView.fs_height-headerHeight-weekdayHeight; + CGFloat contentHeight = self.animator.cachedMonthSize.height-headerHeight-weekdayHeight-_scopeHandle.fs_height; CGFloat padding = weekdayHeight*0.1; if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) { padding = FSCalendarFloor(padding); } if (!self.floatingMode) { - switch (_scope) { - case FSCalendarScopeMonth: { - _preferredRowHeight = _showsPlaceholders ? (contentHeight-padding*2)/6.0 : FSCalendarStandardRowHeight; - break; - } - case FSCalendarScopeWeek: { - _preferredRowHeight = _showsPlaceholders ? contentHeight-padding*2 : FSCalendarStandardRowHeight; - break; - } - } + _preferredRowHeight = _showsPlaceholders ? (contentHeight-padding*2)/6.0 : FSCalendarStandardRowHeight; } else { _preferredRowHeight = FSCalendarStandardRowHeight*MAX(1, FSCalendarDeviceIsIPad*1.5)*_lineHeightMultiplier; } @@ -1697,6 +1691,7 @@ - (void)invalidateViewFrames self.header.needsAdjustingViewFrame = YES; [self.appearance invalidateFonts]; [self.collectionViewLayout invalidateLayout]; + [self setNeedsLayout]; } // The best way to detect orientation diff --git a/FSCalendar/FSCalendarAnimator.m b/FSCalendar/FSCalendarAnimator.m index e7672a8c..ddefcb21 100644 --- a/FSCalendar/FSCalendarAnimator.m +++ b/FSCalendar/FSCalendarAnimator.m @@ -321,6 +321,7 @@ - (void)performTransitionCompletion:(FSCalendarTransition)transition animated:(B self.calendar.bottomBorder.frame = CGRectMake(0, targetBounds.size.height, self.calendar.fs_width, 1); self.calendar.maskLayer.path = self.pendingAttributes.targetMask.CGPath; self.calendar.bottomBorder.fs_top = CGRectGetMaxY(targetBounds); + self.calendar.scopeHandle.fs_bottom = CGRectGetMaxY(targetBounds); self.calendar.needsAdjustingMonthPosition = YES; [self.collectionView reloadData]; [self.calendar.header reloadData]; @@ -332,6 +333,7 @@ - (void)performTransitionCompletion:(FSCalendarTransition)transition animated:(B self.calendar.bottomBorder.frame = CGRectMake(0, targetBounds.size.height, self.calendar.fs_width, 1); self.calendar.maskLayer.path = [UIBezierPath bezierPathWithRect:targetBounds].CGPath; self.calendar.bottomBorder.fs_bottom = targetBounds.size.height; + self.calendar.scopeHandle.fs_bottom = CGRectGetMaxY(targetBounds); [self.calendar.collectionView.visibleCells enumerateObjectsUsingBlock:^(UICollectionViewCell *obj, NSUInteger idx, BOOL * stop) { [CATransaction begin]; [CATransaction setDisableActions:YES];