PDA

View Full Version : Animate buttons in a cell




mrl72
Jan 13, 2011, 08:25 AM
I have tableview with it's cells containing buttons, and on each button I load in image within the cellForRowAtIndexPath method. So something like:


int i=0,i1=0;

while(i<noImages){
UIImage *imageNew = [[UIImage alloc] init] ;
imageNew=[imageNew maskImage:[UIImage imageWithContentsOfFile: item.image]];

UIImage *buttonImageNormal=imageNew;

[button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal ];
[hlcell.contentView addSubview:button];
i++;
}

I have a page full of image thumbnails that are loaded using the method above but they just abruptly appear on the screen. So I would like to display one thumbnail at a time and maybe have them fade up one by one, something like this (at the end of the above):


[button setAlpha:0.0f];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
[button setAlpha:1.0f];
[UIView commitAnimations];


This does in fact work. It fades up the image as it's supposed to. The problem is it fades ALL the images up the same time, which leads me to believe there is no way to do this. Any thoughts?

Cheers.



PhoneyDeveloper
Jan 13, 2011, 08:36 AM
You can use a timer or better use the animation completion routine to start a new animation.

mrl72
Jan 13, 2011, 09:33 AM
Thanks. Looks like that routine still gets called after the table, cells and buttons have been drawn. Since I'm creating the buttons programatically, I really can't see how to start another animation on the buttons that have already been loaded into the tableview.