Skip to content

Instantly share code, notes, and snippets.

@alanjrogers
Created November 11, 2010 03:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alanjrogers/671918 to your computer and use it in GitHub Desktop.
Save alanjrogers/671918 to your computer and use it in GitHub Desktop.
Sample code showing how to add a CATransition to changing the image on a UIImageView
UIImage* newImage = [UIImage imageNamed:context];
// set up an animation for the transition the content
CATransition *animation = [CATransition animation];
[animation setDuration:0.25];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.contentImageView layer] addAnimation:animation forKey:@"SwitchToView1"];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.contentImageView.image = newImage;
[UIView commitAnimations];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment