开发者

Fade animation UITableViewCell

开发者 https://www.devze.com 2023-02-15 15:52 出处:网络
I have a UITableViewController that populates a UITableView with some data that I pull off the net. The data for each cell consists also of an image used as background, which I\'m downloading in a sep

I have a UITableViewController that populates a UITableView with some data that I pull off the net. The data for each cell consists also of an image used as background, which I'm downloading in a separated NSOperation added to a NSOperationQueue with a MaxConcurrentOperationCount set to 4. As long as the image is not downloaded I'm showing a generic placeholder which I would like to replace (fading out/fading in) with the downloaded image once it's being successfully downloaded.

I'm using the following code placed inside the cellForRowAtIndexPath of the UITableViewController.

[UIView beginAnimations:@"fade" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:3.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
cell.placeholderUIImage.alpha = 0.0;
cell.backgroundUIImage.alpha = 1.0;
[UIView commitAnimations];

This is unfortunately just working randomly for a couple of rows, since for the most the background image is set instantly, as if the animation started on one cell would have been "over开发者_C百科written" by the next call of beginAnimations.


UITableView has built-in support for reloading a row with a fading animation, just call [tableView reloadRowsAtIndexPaths:... withRowAnimation:UITableViewRowAnimationFade] and make sure that your cellForRowAtIndexPath doesn't return the UITableViewCell instance that is already in the table.

0

精彩评论

暂无评论...
验证码 换一张
取 消