iOS Camera Countdown Timer - iphone

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

Related

How to take and save 20 photo in one second using objective c

I am creating one photo capture app in which user can take up to 20 photo in one second.
I have already try the AVCam Sample code of apple but it is don't allow to take still Image at 20 FPS.
Is there any other way to take photo at this rate.
see this Demo..Photo Picker
in this demo just check or refer these two classes..
MyViewController.m and
OverlayViewController.m
in OverlayViewController.m class in timedTakePhoto method just set timer with your requirement like bellow..
- (IBAction)timedTakePhoto:(id)sender
{
// these controls can't be used until the photo has been taken
self.cancelButton.enabled = NO;
self.takePictureButton.enabled = NO;
self.timedButton.enabled = NO;
self.startStopButton.enabled = NO;
if (self.cameraTimer != nil)
[self.cameraTimer invalidate];
_cameraTimer = [NSTimer scheduledTimerWithTimeInterval:0.03
target:self
selector:#selector(timedPhotoFire:)
userInfo:[NSNumber numberWithInt:kOneShot]
repeats:YES];
// set time with your requirement above
// start the timer to sound off a tick every 1 second (sound effect before a timed picture is taken)
if (self.tickTimer != nil)
[self.tickTimer invalidate];
_tickTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(tickFire:)
userInfo:nil
repeats:YES];
}
may you can get idea from this and also use this demo for your requirement..
i hope this help you...

NSTimer not running

I've got a program in which I want to code a timer which checks wether the user is idle or not. For that I wrote following code:
if (!idleTimer) {
NSLog(#"make");
idleTimer=[[NSTimer alloc]initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:10.0]interval:10 target:self selector:#selector(idleTimerExceeded) userInfo:nil repeats:NO];
NSLog(#"madetimer with: %f, %#", idleTimer.timeInterval, idleTimer.fireDate);
}else {
NSLog(#"no reset timer: %f", idleTimer.timeInterval);
if (fabs([idleTimer.fireDate timeIntervalSinceNow]) < 9) {
NSLog(#"reset");
[idleTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:10]];
}
}
But somehow my logs show that the interval is always 0.0000 . Which means that something is wrong here. Can anybody help me?
ive never seen a timer look so complicated. try this:
write a method that checks if the user is idle (lets say idleChecker)
then make the timer repeatable and calls that method idleChecker
[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:#selector(idleChecker) userInfo:nil repeats:YES];
remember to declare the idleChecker method in the .h file
take note if u want to stop the timer event then you need to maintain a reference to it
NSTimer aTimer = [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:#selector(idleChecker) userInfo:nil repeats:YES];
then to stop it
[aTimer invalidate];
as for checking if its running i would just stick a nslog message in there stating something like "check for idle user"

progress bar not showing the step by step progress in iphone

Hi all im using progress bar for indicating the status of xml parsing in my app.but it is not showing the step by step updation,instead the progress bar is loading after the entire xml parsing is over,till that time it is stuck and not showing any progress.how to solve this issue.can anyone help me please.
I use the below code
IBOutlet UIProgressView * threadProgressView;
threadProgressView.progress = 0.0;
[self performSelectorOnMainThread:#selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
- (void)makeMyProgressBarMoving
{
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + ((float)1/(float)10);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
else{
/* something else */
}
}
Create a timer on the main thread for every 1/10th of a second. Have it hit your "makeMyProgressBarMoving" function.
myTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:YES];
Then edit your function to look like this:
- (void)makeMyProgressBarMoving {
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + ((float)1/(float)10);
return;
}
//if you got here that means the progress view is greater than 1 so now you can kill your timer that you had running every 1/10th of a second.
[myTimer invalidate];
}

run timer automatically for first and second time

I am new to iPhone,
What I want is that my timer call a function every second but for the very first time it must call the function at 2 second.
Any help will be really appreciated. Thanks
take a variable
BOOL isNotFirstTime;
And in the function that gets triggered after each 4 secs add the following code at the starting
-(void)AfterOneSecondsFuction
{
if(!isNotFirstTime)
{
isNotFirstTime=YES;
return;
}
//YOUR CODE HERE...
}
This is how you give a call to the function
NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(AfterOneSecondsFuction) userInfo:nil repeats:YES];
First schedule a timer and have a BOOL variable say isFirstTime set as YES;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doSomething) userInfo:nil repeats:YES];
and in
- (void)doSomething
{
if(isFirstTime)
{
isFirstTime = NO;
return;
}
// Do something
}

NStimer and for loop

I'm struggling with this. I saw some code where you can do this :
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doActions) userInfo:nil repeats:YES];
}
Then call it in doActions.
Problem is i want to call it while a button is being pressed, and do actions is an IBaction. I keep getting a sigAbrt.
Can someone give me some sample code where you cay change a label from 'on' to 'off' every 1 second while a button is being pressed?
EDIT
i mean if doActions looks like this
- (IBAction) doActions {
for(int j; j<100; j++){
theLabel.hidden != theLabel.hidden;
//Does invalidate timer go here?
}
}
It still isn't clear to me, what you're trying to accomplish: I would have found it much easier, if you simply had it written down in plain english, after all.
That said, here's what I think will get you where you want to go:
// Assuming ivars:
// NSTimer* toggleTimer
// NSUInteger toggleCount
- (void)toggleTimerFired:(NSTimer*)timer
{
if ( toggleCount++ >= 100 ) {
[self stopToggling:self];
return;
}
// do whatever you need to do a hundred times here
}
- (IBAction)stopToggling:(id)sender
{
[toggleTimer invalidate], toggleTimer = nil; // you don't want dangling pointers...
// perform any other needed house-keeping here
}
- (IBAction)startToggling:(id)sender
{
[self stopToggling:self]; // if `startToggling:` will NEVER be called when a timer exists, this line CAN be omitted.
toggleCount = 0;
toggleTimer = [NSTimer scheduledTimerWithTimeInterval:1. target:self selector:#selector(toggleTimerFired:) userInfo:nil repeats:YES];
}
Depending on what exactly you want to do, startToggling: needs to be sent on either touchUpInside or touchDown. In the second case, stopToggling: probably needs to be called on any touchUp... event of the button.
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doActions) userInfo:nil repeats:YES];
}
- (void) doActions {
theLabel.hidden != theLabel.hidden;
}