I'm not sure where you will place the animation, because I donβt know exactly how you shoot the image (maybe you can post the code), but the animation code for the flash screen is white:
//Header (.h) file @property (nonatomic, strong) UIView *whiteScreen; //Implementation (.m) file @synthesize whiteScreen; - (void)viewDidLoad { self.whiteScreen = [[UIView alloc] initWithFrame:self.view.frame]; self.whiteScreen.layer.opacity = 0.0f; self.whiteScreen.layer.backgroundColor = [[UIColor whiteColor] CGColor]; [self.view addSubview:self.whiteScreen]; } -(void)flashScreen { CAKeyframeAnimation *opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"]; NSArray *animationValues = @[ @0.8f, @0.0f ]; NSArray *animationTimes = @[ @0.3f, @1.0f ]; id timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; NSArray *animationTimingFunctions = @[ timingFunction, timingFunction ]; [opacityAnimation setValues:animationValues]; [opacityAnimation setKeyTimes:animationTimes]; [opacityAnimation setTimingFunctions:animationTimingFunctions]; opacityAnimation.fillMode = kCAFillModeForwards; opacityAnimation.removedOnCompletion = YES; opacityAnimation.duration = 0.4; [self.whiteScreen.layer addAnimation:opacityAnimation forKey:@"animation"]; }
You also asked how to control the length of the attenuation. You can do this by setting the values ββin the animationTimes
array. If you're not familiar with how CAKeyframeAnimations
works, then here's a quick break. The total duration of the animation is controlled by opacityAnimation.duration = 0.4
. This makes the animation 0.4 seconds. Now about what animationTimes
does. Each value in the array represents a number from 0.0 to 1.0 and corresponds to an element of the array 'animationValues'. The value in the times array determines the duration of the corresponding keyframe value as a fraction of the total animation duration.
For example, in the animation above, the time array contains values ββof 0.3 and 1.0, which correspond to values ββof 0.8 and 0.0. The total duration is 0.4, so this means that the appearance of a white screen, which has an opacity of initially at 0.0, takes
0.4 * 0.3 = 0.12 seconds.
to increase the opacity to 0.8. The second value, 0.0, makes the layer transparent again. It takes the rest of the time (0.4-0.12 = 0.28 seconds).
source share