Skip to content

Commit

Permalink
Fix issue #310
Browse files Browse the repository at this point in the history
Fix issue #310
  • Loading branch information
WenchaoD committed May 31, 2016
1 parent 6de93e2 commit 0eff5f3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Example/FSCalendarScopeExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Example/ScopeHandleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 14 additions & 19 deletions FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
});
}
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -1697,6 +1691,7 @@ - (void)invalidateViewFrames
self.header.needsAdjustingViewFrame = YES;
[self.appearance invalidateFonts];
[self.collectionViewLayout invalidateLayout];
[self setNeedsLayout];
}

// The best way to detect orientation
Expand Down
2 changes: 2 additions & 0 deletions FSCalendar/FSCalendarAnimator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand Down

0 comments on commit 0eff5f3

Please sign in to comment.