diff --git a/Example/StoryboardExampleViewController.m b/Example/StoryboardExampleViewController.m index f0baf43c..4daae735 100644 --- a/Example/StoryboardExampleViewController.m +++ b/Example/StoryboardExampleViewController.m @@ -92,12 +92,6 @@ - (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar return [calendar dateWithYear:2039 month:5 day:31]; } - -- (void)calendar:(FSCalendar *)calendar didDeselectDate:(NSDate *)date -{ - NSLog(@"Did deselect date %@",[calendar stringFromDate:date]); -} - #pragma mark - FSCalendarDelegate - (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date @@ -118,7 +112,8 @@ - (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date - (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date { NSLog(@"did select date %@",[calendar stringFromDate:date format:@"yyyy/MM/dd"]); - + CGRect frame = [self.calendar frameForDate:date]; + NSLog(@"%@",NSStringFromCGRect(frame)); } - (void)calendarCurrentPageDidChange:(FSCalendar *)calendar diff --git a/FSCalendar/FSCalendar.h b/FSCalendar/FSCalendar.h index 1dba8e83..71e2e501 100644 --- a/FSCalendar/FSCalendar.h +++ b/FSCalendar/FSCalendar.h @@ -379,13 +379,27 @@ IB_DESIGNABLE - (void)deselectDate:(NSDate *)date; /** - * Change the current page of the calendar. + * Changes the current page of the calendar. * * @param currentPage Representing weekOfYear in week mode, or month in month mode. * @param animated YES if you want to animate the change in position; NO if it should be immediate. */ - (void)setCurrentPage:(NSDate *)currentPage animated:(BOOL)animated; +/** + * Returns the frame for a non-placeholder cell relative to the super view of the calendar. + * + * @param date A date is the calendar. + */ +- (CGRect)frameForDate:(NSDate *)date; + +/** + * Returns the midpoint for a non-placeholder cell relative to the super view of the calendar. + * + * @param date A date is the calendar. + */ +- (CGPoint)centerForDate:(NSDate *)date; + @end #pragma mark - DateTools diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index ea280e41..7505e4c3 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -810,6 +810,25 @@ - (void)setCurrentPage:(NSDate *)currentPage animated:(BOOL)animated } } +- (CGRect)frameForDate:(NSDate *)date +{ + if (!self.superview) { + return CGRectZero; + } + CGRect frame = [_collectionViewLayout layoutAttributesForItemAtIndexPath:[self indexPathForDate:date]].frame; + frame = [self.superview convertRect:frame fromView:_collectionView]; + return frame; +} + +- (CGPoint)centerForDate:(NSDate *)date +{ + CGRect frame = [self frameForDate:date]; + if (CGRectIsEmpty(frame)) { + return CGPointZero; + } + return CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame)); +} + - (void)setHeaderHeight:(CGFloat)headerHeight { if (_headerHeight != headerHeight) {