Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the effects of UIView transitionWithView

Using the code below I have successfully made my UIImageView fade in its image.

[UIView transitionWithView:myCell.myImageView duration:2.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    myCell.myImageView.image = myImage;
} completion:NULL];

However, when the cell is reused I need to remove this image. When reused it shows the last image(shown before it was reused) and then transitions into the image it is supposed to be, instead of transitioning from no image into the image it is supposed to be.

What I have tried:

-(void)prepareForReuse {
    [super prepareForReuse];

// More is obviously needed than just setting image to nil when using a transition
self.myImageView.image = nil;

[self.myImageView setNeedsDisplay];

// but I also tried removing all animations
[self.myImageView.layer removeAllAnimations];

// and I even tried removing the sublayers, but still no success.
[self.myImageView.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
}

Any help is appreciated, but please don't answer if you don't understand what the issue is. Comment instead so I can explain better if needed.

Thanks!

like image 253
AlexanderN Avatar asked Feb 16 '15 06:02

AlexanderN


1 Answers

You could make use of the callback

tableView:didEndDisplayingCell:forRowAtIndexPath:

This is called is just as the cell goes outside the visible area.
Try setting the image to nil or no image over here. Should work.

like image 98
Samarth Avatar answered Oct 19 '22 02:10

Samarth