简体   繁体   English

相机拍摄时闪光屏白色?

[英]Flash screen white at moment of camera capture?

I'd like to flash (and then fade out) the screen right at the moment of camera capture to give the user the indication that a picture has been taken (besides just an auditory clue). 我想在拍摄相机时立即闪烁(然后淡出)屏幕,以便向用户提供已拍摄照片的指示(除了听觉线索之外)。

Where would such an animation be placed? 这样的动画会放在哪里? Also, how would it be implemented such that I can control the duration of the fadeout? 另外,如何实现我可以控制淡出的持续时间?

Note: I've created a custom overlay for my particular camera picker. 注意:我为我的特定相机选择器创建了一个自定义叠加层。

Anything indicating that a picture has been taken is what I am looking for. 任何表明照片被拍摄的东西都是我要找的东西。

I'm not sure where you would place the animation because I don't know how exactly you capture the picture (maybe you could post the code), but here's the code for an animation to flash the screen 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 fadeout duration. 您还询问了如何控制淡出持续时间。 You can do this by adjusting the values in the animationTimes array. 您可以通过调整animationTimes数组中的值来完成此操作。 If you're not familiar with how CAKeyframeAnimations work, then here's quick briefer. 如果您不熟悉CAKeyframeAnimations工作方式,那么请快速浏览一下。 The total duration of the animation is controlled by the opacityAnimation.duration = 0.4 . 动画的总持续时间由opacityAnimation.duration = 0.4 This makes the animation 0.4 seconds long. 这使得动画长达0.4秒。 Now onto what animationTimes does. 现在进入animationTimes作用。 Each value in the array is a number between 0.0 and 1.0 and corresponds to an element in the 'animationValues' array. 数组中的每个值都是介于0.0和1.0之间的数字,并且对应于'animationValues'数组中的元素。 The value in the times array defines the duration of the corresponding keyframe value as a fraction of the total duration of the animation. times数组中的值将相应关键帧值的持续时间定义为动画总持续时间的一部分。

For example, in the above animation, the times array contains the values 0.3 and 1.0, which correspond to the values 0.8 and 0.0. 例如,在上面的动画中,时间数组包含值0.3和1.0,它们对应于值0.8和0.0。 The total duration is 0.4, so that means that the whiteScreen view which has its opacity initially at 0.0, takes 总持续时间为0.4,因此这意味着最初的不透明度为0.0的whiteScreen视图占用

0.4 * 0.3 = 0.12 seconds.

to raise the opacity to 0.8. 将不透明度提高到0.8。 The second value, 0.0, makes the layer go transparent again. 第二个值0.0使图层再次变为透明。 This takes up the remainder of the time (0.4 - 0.12 = 0.28 seconds). 这占用剩余的时间(0.4-0.12 = 0.28秒)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM