Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView change Background Color and setImage not working during Animation

As the title said, it's very strange, did you agree?

So , if someone found your codes

imageView.backgroundColor = [UIColor greenColor]; 

or

imageView.image = [UIImage imageName:@"angryBird"];" 

are not working. Just mind that if your imageView is animating , or whether the animation has been removed or not.

----------The Answer Below---------------

Just stop animating before you set image and change background of the animating UIImageView.

UIImageView* imageView = [UIImageView alloc] init];
//......do sth. like setFrame ...
imageView.images = [NSArray arrayWithObjects....]; // set the animation images array 
imageView.animationDuration = 1.0;
[imageView startAnimating];
//......do sth.
[imageView stopAnimating];        // **** do not forget this!!!!! ****
imageView.backgroundColor = [UIColor greenColor];
imageView.image = [UIImage imageName:@"angryBird"];

When you performSelector: withObject: afterDey:1.0s , in the selector method , also, you need to stopAnimating too, and then setImage or change background color.

like image 985
isaacselement Avatar asked May 31 '13 12:05

isaacselement


2 Answers

Try to change background color and changing the image once animation is complete. it will simply work for you.

like image 121
Vinod Singh Avatar answered Oct 04 '22 04:10

Vinod Singh


Try this:

[UIView animateWithDuration:1.0 animations:^(){} completion:^(BOOL finished){}];
like image 28
Leta0n Avatar answered Oct 04 '22 03:10

Leta0n