UITableView how to catch the end of an animation?

I have a UITableView with many rows. It looks like an accordion: http://docs.jquery.com/UI/Accordion Main cells have subelements, subelements also have subelements. So this is a three-level tableView.

Well, when the user selects a cell, it expands (or collapses) the sublifts with the string animation. But I need to set a new size for tableView and scrollView.

I do all this in this method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

Problem: When the user clicks on the cell, then quickly tap the sub, the second animation will not be performed, so the subelements of level 2 are not displayed. But the size was set (given that the subelements of level 2 are shown).

I actually play with time to handle this ... but it really sucks.

Here is an example of my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// Checking with times (with 0,5 second interval in order to be sure that the previous animation is finished !)

// Setting tableView & scollView heights

[tableView beginUpdates];
if(position.isExpanded == YES)
    [tableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationBottom];
else 
    [tableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
[tableView endUpdates];
}

So, I would like to catch the end of this animation. Or, playing with some kind of semaphore (but I only have 1 process ...) Any ideas to fix this?

Please keep in mind in your answers that I am really new to iPhone development.

Thank.

+3
source share
2 answers

Animation is controlled by an instance of the class CAAnimation. This class supports the method - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flagthat will be passed to the delegate of this instance. This information is commonly used to obtain completion information.

, UIView Class. , - UITableView. , UIView, .

0

:

, NSArray *animationKeys = [cell.layer animationKeys]; CAAnimation *animation = [cell.layer animationForKey:_a_key_];. , .

0

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


All Articles