aroooo
aroooo

Reputation: 5076

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!

Upvotes: 3

Views: 3689

Answers (1)

Herz Rod
Herz Rod

Reputation: 831

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

Upvotes: 4

Related Questions