简体   繁体   English

iOS相机倒数计时器

[英]iOS Camera Countdown Timer

I'm looking for the cleanest way to have a countdown timer fire when a user hits the 'take picture' button. 当用户点击“拍照”按钮时,我正在寻找最简洁的方法让倒数计时器触发。 Is there any easy way to do this? 有没有简单的方法来做到这一点?

One solution I'm thinking of is to just have a label that updates every second, but is there a way to get it working like Photobooth? 我想到的一个解决方案就是让每一秒都有一个标签更新,但有没有办法让它像Photobooth一样工作?

Also, at the last second before the photo is about to be taken I'd like for an image to be displayed briefly while the image is being taken. 此外,在即将拍摄照片之前的最后一秒,我希望在拍摄图像时能够短暂显示图像。 How can I go about this? 我怎么能这样做?

Any help would be great, thanks! 任何帮助都会很棒,谢谢!

- (IBAction)takePicture:(id)sender {
    theTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateLabel:) userInfo:nil repeats:NO];
}

- (void)updateLabel:(NSTimer *)timer {
    _timeLabel.text = [NSString stringWithFormat:@"%d", time];
    time = time - 1;
    if (time == 0) {
        [theTimer invalidate];
        [_timeLabel performSelector:@selector(setText:) withObject:@"Photo taken!" afterDelay:1.0];
        //Code for image shown at last second
    } else {
        theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel:) userInfo:nil repeats:NO];
    }
}

Hope this helps ;) 希望这可以帮助 ;)

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

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