Interrupting UITableView cell resize animation?

I have a UITableView, and when it stops scrolling (scrollViewDidEndDecelerating :) the height of the current cell expands by setting the currentRow variable 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]; }; 

Animation works fine, but temporarily prohibits scrolling / interactively viewing a table. Therefore, if I touch the screen while the cell is expanding, I cannot scroll unless I try again.

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

+6
source share
5 answers

You can use this method to stop the animation,
but I’m not sure that it will not cause problems.

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

Try adding this to your TableViewController.

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

or try adding a gesture recognizer to the application window, and then call stopAinimations on the gesture trigger.

+4
source

The UITableView animation system is completely opaque. The API does not allow you to modify or redefine what happens, except what type of animation occurs for insertions / deletions. Browse the header file and view stack traces.

Thus, there is no practical way to prevent UITableView animations from blocking touches, nor is it necessary. This can lead to the manipulation of an overloaded cell. So, if you do not like EXC_BAD_ACCESS errors, do not do this.

Please note that this user interaction is disabled for all UITableView animations, not just updates - insertions, deletions, and reloads are handled the same way.

It seems like a sensible hook to have in a UITableView animation, so be sure to send the bug report to Apple and maybe we'll see this in a future improvement.

+1
source

If you are using iOS 7+, you can try calling table updates inside the [UIView performWithoutAnimation:] block.

+1
source

Cannot interrupt tableview animation, and this is not recommended. If you want the table view to be responsible at the first touch, you can use the reloadData method instead of beginUpdates , try using the reloadSection method. This may help, but preventing animation is not a good idea.

+1
source

Try the following:

 [CATransaction begin]; [self.tableView beginUpdates]; [CATransaction setCompletionBlock: ^{ // Code to be executed upon completion CGFloat current_offset = self.tableView.contentOffset.y; currentRow = [self.tableView indexPathForRowAtPoint:CGPointMake(0, current_offset)].row; }]; [self.tableView endUpdates]; [CATransaction commit]; 

Finally, you may want to transfer the animation also for tableview

+1
source

Source: https://habr.com/ru/post/971259/


All Articles