1000Memories / TMQuiltView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

1 photo disappears

jesusgarza opened this issue · comments

Modify TMDemoQuiltViewController to have only one cell:

const NSInteger kNumberOfCells = 1;

Run the demo project and scroll up the view until you completely hide the photo in the upper margin. It seems as if the photo doesn't come back down.

I also observe this question. Actually as long as the ALL of images of one column get scrolled out of the top of the view, they won't come back.
I try to trace, it looks like, the 'bottom' of that column won't change after that. However I 'guess' (since I don't understand the code completely) it might have something to do with the logic in the code below, wish someone could help since this situation is quite common. Thanks. (One can change all of the images' sizes to 1024 * 768 to reproduce such problem)

    while ((*top > 0) && [TMQuiltView isRect:[self rectForCellAtIndex:*top column:i] entirelyInOrBelowScrollView:self]) {
        if ([TMQuiltView isRect:[self rectForCellAtIndex:*top - 1 column:i] partiallyInScrollView:self]) {
            NSIndexPath *newIndexPath = [indexPaths objectAtIndex:*top - 1];
            TMQuiltViewCell* newCell = [self.dataSource quiltView:self cellAtIndexPath:newIndexPath];
            newCell.frame = [self rectForCellAtIndex:*top - 1 column:i];
            [indexPathToView setObject:newCell forKey:newIndexPath];
            [self addSubview:newCell];
        }
        (*top)--;
    }

The cause of this problem is cell-reuse. The following code removes the cell from View when a cell leaves the visible rect, but in this case a new cell is not re-drawn when it bounces back into the frame:
for (NSIndexPath* indexPath in [indexPathToView allKeys]) {
TMQuiltViewCell *view = [indexPathToView objectForKey:indexPath];
if (![TMQuiltView isRect:view.frame partiallyInScrollView:self]) { // Rect intersection?
[indexPathToView removeObjectForKey:indexPath];
// Limit the size on the reuse pool
if ([[self reusableViewsWithReuseIdentifier:view.reuseIdentifier] count] < 10) {
[[self reusableViewsWithReuseIdentifier:view.reuseIdentifier] addObject:view];
}
[view removeFromSuperview];
// Only harvest once per call to make things smoother
//break;
}
}

A somewhat hacky fix would be only call that code when contentSize.height > frame.size.height, since cell reuse is unnecessary if the content size is smaller than view frame. But that does not address the root issue of not redrawing the cell upon the view bouncing back.

I've just run at the same problem. Any progress on this?

Good Job,the problem has gone!Thank you!

@pawartur good work, Thank U!!