Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions TimesSquare/TSQCalendarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
*/
@property (nonatomic) BOOL pagingEnabled;

/** Whether or not the calendar snaps the nearest edge of a row to the top of its bounds.

This property is similar to `pagingEnabled`, except the snapping is to rows rather than months.
Paging takes precedence over snapping to row boundaries.
*/
@property (nonatomic) BOOL snapsToRows;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename pagingEnabled to snapsToMonths for parallelism here?


/** The distance from the edges of the view to where the content begins.

This property is equivalent to the one defined on `UIScrollView`.
Expand Down
10 changes: 10 additions & 0 deletions TimesSquare/TSQCalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
}
CGRect sectionRect = [self.tableView rectForSection:section];
*targetContentOffset = sectionRect.origin;
} else if (self.snapsToRows) {
// Find the frame of the cell the scroll will end in
NSIndexPath *targetIndexPath = [self.tableView indexPathForRowAtPoint:*targetContentOffset];
CGRect targetCellRect = [self.tableView rectForRowAtIndexPath:targetIndexPath];
// Round the scroll finish point to the nearest cell boundary
if (targetContentOffset->y < targetCellRect.origin.y + targetCellRect.size.height/2.) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this may be idiomatic C, I'm a bit wary of introducing this kind of struct pointer notation. Also 2.0.

targetContentOffset->y = targetCellRect.origin.y;
} else {
targetContentOffset->y = targetCellRect.origin.y + targetCellRect.size.height;
}
}
}

Expand Down