Skip to content
Browse files

On insertion, don't scroll beyond the end of the contents.

  • Loading branch information...
1 parent 0a2911b commit 2b4e37c62ad1f5d9f4079c142614a28c24f0036e BJ Homer committed Nov 29, 2010
Showing with 13 additions and 2 deletions.
  1. +13 −2 Classes/HSSidebarView.m
View
15 Classes/HSSidebarView.m
@@ -204,15 +204,26 @@ - (void)insertRowAtIndex:(NSUInteger)anIndex {
if (imageTop < scrollTop) {
// It's off the top of the screen
- CGFloat delta = scrollTop - imageTop + 10 + (rowHeight / 2);
+ CGFloat distanceBetweenFrameAndRowTop = (int)imageTop % (int)rowHeight;
+ CGFloat delta = scrollTop - imageTop + distanceBetweenFrameAndRowTop;
+
+ if (anIndex != 0) {
+ // Show a bit of the previous row, if one exists
+ delta += (rowHeight / 2);
+ }
CGPoint newOffset = CGPointMake(oldOffset.x, oldOffset.y - delta);
[_scrollView setContentOffset:newOffset animated:YES];
}
else if (scrollBottom < imageBottom) {
// It's off the bottom of the screen
+ CGFloat distanceBetweenFrameAndRowBottom = rowHeight - ((int)imageBottom % (int)rowHeight);
- CGFloat delta = imageBottom - scrollBottom + 10 + (rowHeight / 2);
+ CGFloat delta = imageBottom - scrollBottom + distanceBetweenFrameAndRowBottom;
+ if (anIndex != [self imageCount] - 1) {
+ // Show a bit of the next row, if one exists.
+ delta += (rowHeight / 2);
+ }
CGPoint newOffset = CGPointMake(oldOffset.x, oldOffset.y + delta);
[_scrollView setContentOffset:newOffset animated:YES];

0 comments on commit 2b4e37c

Please sign in to comment.
Something went wrong with that request. Please try again.