gpt4 book ai didi

ios - 相机捕捉时闪屏变白?

转载 作者:可可西里 更新时间:2023-11-01 03:44:11 25 4
gpt4 key购买 nike

我想在相机拍摄时立即闪烁(然后淡出)屏幕,以向用户表明照片已拍摄(除了听觉提示)。

这样的动画放在哪里?另外,如何实现才能控制淡出的持续时间?

注意:我已经为我的特定相机选择器创建了一个自定义叠加层。

任何表明已拍摄照片的东西都是我要找的东西。

最佳答案

我不确定你会将动画放在哪里,因为我不知道你是如何捕捉图片的(也许你可以发布代码),但这里是让屏幕闪白的动画代码:

//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"];
}

您还询问了如何控制淡出持续时间。您可以通过调整 animationTimes 数组中的值来实现。如果您不熟悉 CAKeyframeAnimations 的工作原理,那么这里有一个简短的介绍。动画的总持续时间由 opacityAnimation.duration = 0.4 控制。这使得动画长 0.4 秒。现在看看 animationTimes 做了什么。数组中的每个值都是介于 0.0 和 1.0 之间的数字,并且对应于“animationValues”数组中的一个元素。 times 数组中的值将相应关键帧值的持续时间定义为动画总持续时间的一部分。

例如,在上面的动画中,时间数组包含值 0.3 和 1.0,它们对应于值 0.8 和 0.0。总持续时间为 0.4,这意味着最初不透明度为 0.0 的 whiteScreen View 需要

0.4 * 0.3 = 0.12 seconds.

将不透明度提高到 0.8。第二个值 0.0 使图层再次透明。这会占用剩余的时间(0.4 - 0.12 = 0.28 秒)。

关于ios - 相机捕捉时闪屏变白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11731930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com