Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interrupt UITableView cell resize animation?

I have a UITableView, and when it stops scrolling (scrollViewDidEndDecelerating:) the height of the current cell expands by setting the variable currentRow and reloading:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGFloat current_offset = self.tableView.contentOffset.y;
    currentRow = [self.tableView indexPathForRowAtPoint:CGPointMake(0, current_offset)].row;
    [self.tableView beginUpdates];
    [self.tableView endUpdates];
};

The animation works fine, but it temporarily prevents the tableview from being scrollable/interactive. So if I touch the screen while the cell is expanding, I end up not being able to scroll unless I try again.

Is there a workaround or another way to achieve the same effect?

like image 399
Michael Wilson Avatar asked Jun 23 '14 20:06

Michael Wilson


1 Answers

You can use this method, to stop animations,
but I'm not sure that it will not make problems.

- (void)stopAnimations
{
    for (UITableViewCell *cell in [self.tableView visibleCells]) {
        [cell.layer removeAllAnimations];
    }
}

Try adding this on your TableViewController

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self stopAnimations];
}

or try to add tap gesture recognizer to Application's window and then call stopAinimations on gesture trigger.

like image 134
l0gg3r Avatar answered Sep 18 '22 12:09

l0gg3r