English 中文(简体)
电话 A. 时间缩减的背景
原标题:iphone Timer countdown in background

hi i want make a simple timer whit picker and label.

在我的经历之前,一切都做了大量工作,我不理解为什么? i 放弃某种东西?

页: 1

 - (void)tick {

//sottraiamo uno dal countdown
countdown--;

//controlliamo che il valore di countdown sia minore di zero
if (countdown < 0) {
    NSLog(@"controllo");

    //se è minore di zero allora il timer è finito
    //Incvochiamo l azione playSound per suonare l allarme
    [self playSound];

    //Invochiamo il metodo fermaIlTimer per fermare il timer
    [self fermaIlTimer];

    //Arrestiamo il codice
    return;

    //Inibisce lo standby
    [UIApplication sharedApplication].idleTimerDisabled = YES;
}



//Assegnamo alla proprietà text della UILabel la stringa restituita dal metodo formattazioneLabel
self.countdownLabel.text = [self formattazioneLabel];
 }





#pragma mark Azioni

//Impostiamo l azione del pulsante newTime
- (IBAction)newTime:(id)sender {

    //controlliamo se sta andando e se si fermiamo il blocco di codice con il return
    if (isRunning) return;

    //Impostiamo il countdown con il metodo dateWithTimeIntervalSinceNow prendendo il tempo dal valore della ruota di selezione + 1
    countdown = [self getPickerTime];

    //Assegnamo alla proprietà text della UILabel la stringa restituita dal metodo formattazioneLabel
    self.countdownLabel.text = [self formattazioneLabel];
}

//Start
- (IBAction)start:(id)sender {

    if (isRunning == NO && isPlay == NO){


    //Impostiamo su si il booleano isRunning
    isRunning = YES;

    //Impostiamo il countdown con il metodo personalizzato
    countdown = [self getPickerTime];

    //Invochiamo il primo tick 
    [self tick];

    //Avviamo la data con il metodo scheduledTimerWithTimeInterval che ogni secondo invoca il metodo tick
    self.theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(tick) userInfo:nil repeats:YES];

    //imposta la font di rosso
    self.countdownLabel.textColor = [UIColor redColor];

        //modifiche fondo

        fondo.image = [UIImage imageNamed: @"Bck_timerII.png"];
        myPicker.hidden = YES;
        copertura.hidden = YES;
        start.hidden = YES;
        stop.hidden = NO;
        pausa.hidden = NO;

        }

}
问题回答

页: 1

[UIApplication sharedApplication].idleTimerDisabled = YES;

从未执行过,因为你在前线上有一个“返回”;





相关问题
How do I wait for a TTimer to finish?

I have a TFrame (fraDisplay) with a TTimer (timAnimateDataChange). The timer is used to control a small animation. In the form containing the frame I want to have a method that does something like ...

How to tell if an ajax timer has gone off at page_load

I have a web application and I m attempting to put an ajax timer control in it to give me a post back every 10-20 seconds. (possibly longer depending on performance). I have a lot of dynamically ...

Got an error 1120 ~ Access of undefined property

This is not your typical 1120. I know better than to have buttons/MCs without instance names on the timeline. Nope, this problem resides in a I timer I built from script I found online. The undefined ...

what is the right way to call the Timer ElapsedEventHandler

i have a timer that calls its even handler method every 30 seconds. but i want to initialy call this method. the signature of the event handler method is void TimerElapsed_GenerateRunTimes(object ...

Timer for a polling windows service

I wrote a Timer class in order to use it within a windows service that is polling another system. I did this because I had two issues that the System.Timers.Timer is not addressing. The Elapsed ...

Using C# Timer to stop executing a Program

I want a program to stop executing for a certain amount of time. And i want this to happen in regular intervals. For example, i want a program to run for 5 minutes and then it should stop for 2 ...

热门标签