我正在尝试复制 iPhone 相机应用程序的默认快门动画。
也许有人尝试过这样做并有一些提示可以分享?
好吧,我在某个地方找到了这个:
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"];
这是默认的 iPhone 相机快门动画。
在 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")