views:

346

answers:

1

Hi I want to perform a shrink animation on a UITableVIew. I experimented a bit and found out that the animation runs much faster when I shrink a UIImageView with an image of the current state of the tableview instead of shrinking the table view itself.

I grabbed the image in a method in my main viewcontroller prior to the animation:

UIGraphicsBeginImageContext(mainTableView.bounds.size);

[resizeContainer.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

Works like a charm, at least almost. On very rare occasions I get weird graphic glitches, where the UIImage starts to overlap a toolbar that lies underneath it.

I just want to make sure that I am getting the image in the right way. I am laking the necessary understand of GraphicContexts to be sure about it.

To cut a long story short, is my code correct?

Thx

A: 

In what way did you animate the table? I haven't had problems with it animating slowly. Here is an example of what I did when I had to resize my table:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[mainTableView setFrame:CGRectMake(0,43,320,176)];
[UIView commitAnimations];

The reason I would suggest not just taking a screenshot but actually animating the table is because the animation could possibly start as the table is still scrolling. For instance the user just happened to flick the table as it started animating then you would have a jump to the new state when you fade out the "screen shot" that you took.

Marcin
I am doing a shrink (like the switch tabs animation in safari). My tableCells have heaps of subviews. The animation was really bumpy before I switched to this method.
Monobono