简体   繁体   中英

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?

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 ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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