Call another screen after few seconds without user interaction

0

I need to put the following behavior in my app:

After a few seconds without a user touching the screen, for example 10 seconds, the app will display another screen showing an image. And when the user touches the screen, the image screen disappears and returns to the previous screen. And while the user is interacting with the app nothing appears.

The behavior will look like that of a screen saver.

    
asked by anonymous 30.07.2014 / 15:59

2 answers

1

You can also use the methods of UIResponder that your AppDelegate inherits.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    // Ao detectar o toque, reseta o timer
    [self resetarTimerDeInatividade];
}

- (void)resetarTimerDeInatividade {
    if (self.interacaoTimer) {
        // Caso o timer esteja ativo, invalidamos ele
        [self.interacaoTimer invalidate];
        self.interacaoTimer = nil;
    }

    NSInteger tempoMaximoSemInteracao = 10; // em segundos

    // Iniciamos o timer novamente
    self.interacaoTimer = [NSTimer scheduledTimerWithTimeInterval:tempoMaximoSemInteracao
                                                           target:self
                                                             selector:@selector(tempoInativoExcedido)
                                                         userInfo:nil
                                                          repeats:YES];
}

- (void)tempoInativoExcedido{
    // Aqui você pode disparar a exibição da sua tela temporária
}
    
31.07.2014 / 06:32
1

One possible solution is to use a timer that is reset at each user interaction. When the time limit is reached, the timer will call the specified selector:

- (void)resetTimer {

    if (timer) {
        [timer invalidate];
        timer = nil;
    }

    timer = [NSTimer scheduledTimerWithTimeInterval:10
                                             target:self
                                           selector:@selector(idleTimerExceeded)
                                           userInfo:nil
                                            repeats:NO];
}

- (UIResponder *)nextResponder {

    [self resetTimer];
    return [super nextResponder];
}

You can use the viewDidAppear method to start the timer.

    
30.07.2014 / 17:36