Josh Kahane Josh Kahane - 1 year ago 107
iOS Question

Fade/dissolve when changing UIImageView's image

Rather than creating two

, it seems logical to simply change the
of one view. If I do that, is there anyway of having a fade/cross dissolve between the two images rather than an instant switch?

Answer Source

Edit: there is a better solution from @algal below.

Another way to do this is by using predefined CAAnimation transitions:

CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];
view1.hidden = YES;
view2.hidden = NO;

See the View Transitions example project from Apple:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download