Skip to content

Instantly share code, notes, and snippets.

@benjaminbojko
Created November 6, 2012 22:18
Show Gist options
  • Save benjaminbojko/4028025 to your computer and use it in GitHub Desktop.
Save benjaminbojko/4028025 to your computer and use it in GitHub Desktop.
Flip and Reload a single UIView
/// based on http://stackoverflow.com/questions/347721/how-do-i-apply-a-perspective-transform-to-a-uiview
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseIn animations:^{
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -500;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI_2, 0.0f, 1.0f, 0.0f);
[self.view.layer setTransform:rotationAndPerspectiveTransform];
} completion:^(BOOL finished) {
// REFRESH YOUR VIEW HERE
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -500;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, -M_PI_2, 0.0f, 1.0f, 0.0f);
[self.view.layer setTransform:rotationAndPerspectiveTransform];
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.view.layer setTransform:CATransform3DMakeRotation( 0.0f, 0.0f, 1.0f, 0.0f)];
} completion:^(BOOL finished) {
}];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment