Last active
May 16, 2018 19:42
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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