1
votes

I am currently sliding in an animated image from the right of the screen using CATransition:

CATransition *transition = [CATransition animation];
transition.duration = TRANSITION_DURATION;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.layer addAnimation:transition forKey:nil];
self.image = [UIImage animatedImageNamed:prefix duration:ANIMATION_DURATION];

My question is, how do I slide the image out? Once the image animation cycles through, I want to send it off the screen in the direction from whence it came, i.e. TransitionToRight, but there doesn't seem to be such a transition type. Please suggest how I might accomplish this reverse transition.

Here is how I might write it, if such a reverse transition existed:

[self performSelector:@selector(removeAnimatedImage) withObject:nil afterDelay:ANIMATION_DURATION];

and inside removeAnimatedImage, I would create another CATransition animation with this reverse direction to send it off the screen.

2

2 Answers

1
votes

Did you try the kCATransitionFromLeft version of the push transition? It should be the inverse of FromRight.

0
votes

Not the ideal solution, but one hack is to either animate a change in frame bounds, or applying a translation transform animation:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:TRANSITION_DURATION];

if (enteredFromRight) {
    self.transform = CGAffineTransformMakeTranslation(SCREEN_SPACE_WIDTH, 0);
} else {
    self.transform = CGAffineTransformMakeTranslation(-SCREEN_SPACE_WIDTH, 0);
}
[UIView commitAnimations];