Stop UITableViewCells from animating while animating a UITableView

I am animating a UITableView. I want the table view to be open as shown below:

http://www.youtube.com/watch?v=XIGJLbiRsXE

However, it opens as follows:

http://www.youtube.com/watch?v=UJUX-ILCB_0

Notice how the table cells themselves come to life. How can i stop this?

I use autorun. So the code:

[theView addSubview:theTable]; [theTable reloadData]; [theTable invalidateIntrinsicContentSize]; [UIView animateWithDuration:.33 animations:^{ [theView layoutIfNeeded]; }]; 

Other information that may or may not matter:

  • The table view role is scrollView

  • I overridden the intrinsicContentSize of the table view to return the height of all cells as a table, so the table view will not scroll

  • I am changing the data source in the table view before displaying it

+6
source share
4 answers

I had a similar problem and I was able to stop the animation in a UITableViewCell using the UIView performWithoutAnimation: method.

Use the tableView:willDisplayCell:forRowAtIndexPath: UITableViewDelegate method to get a cell reference before displaying it. Then, in the performWithoutAnimation: block, call layoutIfNeeded on the cell object to enable it to compose its subzones:

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [UIView performWithoutAnimation:^{ [cell layoutIfNeeded]; }]; } 
+12
source

It may be too late to answer this question, but the problem in such cases, as a rule, lies in the animation block, which captures all pending layouts planned in the next run cycle.

The solution I am using. I call layoutIfNeeded before the animation (before setting or canceling any restrictions), and then inside the animation block.

In your case, it will be something like this,

 [theView addSubview:theTable]; [theTable reloadData]; [theView layoutIfNeeded]; [theTable invalidateIntrinsicContentSize]; [UIView animateWithDuration:.33 animations:^{ [theView layoutIfNeeded]; }]; 
+1
source

Have you considered animations instead of the opaque spy located above the table view?

 [theView addSubview:theTable]; [theTable reloadData]; UIView *subview = [[UIView alloc] initWithFrame:theTable.frame]; subview.backgroundColor = [UIColor whiteColor]; [theView addSubview:subview]; [UIView animateWithDuration:0.33 animations:^{ subview.frame = CGRectMake(subview.frame.origin.x, subview.frame.size.height, subview.frame.size.width, 0.0); }]; 
0
source

Try laying out the table first before you call [layoutViewIfeded] inside the animation block. Ideally, you can divide in parts, and in 0.33 seconds you can get a scroll bar on the table, but the goal is to resize the table layout outside the animated block.

0
source

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


All Articles