Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shutter animation AVFoundation iphone

Tags:

ios

camera

I am trying to replicate iPhone Camera app default shutter animation.

Maybe anyone has tried doing that and have some hints to share?

like image 226
spacecash21 Avatar asked Nov 13 '12 22:11

spacecash21


2 Answers

Well, I found this somewhere:

     CATransition *shutterAnimation = [CATransition animation];
     [shutterAnimation setDelegate:self];
     [shutterAnimation setDuration:0.6];

     shutterAnimation.timingFunction = UIViewAnimationCurveEaseInOut;
     [shutterAnimation setType:@"cameraIris"];
     [shutterAnimation setValue:@"cameraIris" forKey:@"cameraIris"];
     CALayer *cameraShutter = [[CALayer alloc]init];
     [cameraShutter setBounds:CGRectMake(0.0, 0.0, 320.0, 425.0)];
     [self.layer addSublayer:cameraShutter];
     [self.layer addAnimation:shutterAnimation forKey:@"cameraIris"];

It's the default iPhone camera shutter animation.

like image 69
spacecash21 Avatar answered Oct 01 '22 17:10

spacecash21


And in Swift 3.0...

let shutterAnimation = CATransition.init()
shutterAnimation.duration = 0.6
shutterAnimation.timingFunction = CAMediaTimingFunction.init(name: 
kCAMediaTimingFunctionEaseInEaseOut)
shutterAnimation.type = "cameraIris"
shutterAnimation.setValue("cameraIris", forKey: "cameraIris")

let shutterLayer = CALayer.init()
shutterLayer.bounds = self.view.bounds
self.view.layer.addSublayer(shutterLayer)
self.view.layer.add(shutterAnimation, forKey: "cameraIris")
like image 42
magneticrob Avatar answered Oct 01 '22 18:10

magneticrob