Skip to content

Instantly share code, notes, and snippets.

@michaelochs
Last active May 16, 2018 19:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michaelochs/5633296 to your computer and use it in GitHub Desktop.
Save michaelochs/5633296 to your computer and use it in GitHub Desktop.
This is a segue that does an iris animation like the iOS camera app. Note: The name cameraIris is private API and might lead to rejection!
@implementation IrisSegue
- (void)perform
{
[self.sourceViewController presentViewController:self.destinationViewController animated:NO completion:^{
// don't ask - it just works with two calls to dispatch_async
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
NSString* shutterAnimationName = @"cameraIris";
CATransition *shutterAnimation = [CATransition animation];
[shutterAnimation setDuration:0.5];
shutterAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[shutterAnimation setType:shutterAnimationName];
[shutterAnimation setStartProgress:0.5];
UIViewController* destination = self.destinationViewController;
CALayer *cameraShutter = [[CALayer alloc]init];
[cameraShutter setBounds:destination.view.layer.bounds];
[destination.view.layer addSublayer:cameraShutter];
[destination.view.layer addAnimation:shutterAnimation forKey:shutterAnimationName];
});
});
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment