【问题标题】:Flash screen white at moment of camera capture?相机拍摄时闪屏白屏?
【发布时间】:2012-07-31 01:29:32
【问题描述】:

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

这样的动画应该放在哪里?另外,如何实现以便我可以控制淡出的持续时间?

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

任何表明已拍摄照片的内容就是我要查找的内容。

【问题讨论】:

    标签: ios animation camera image-capture


    【解决方案1】:

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

    //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 数组中的值将相应关键帧值的持续时间定义为动画总持续时间的一部分。

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

    0.4 * 0.3 = 0.12 seconds.
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 2012-04-18
      相关资源
      最近更新 更多