Pergunta

Estou trabalhando em um aplicativo iOS, onde quero carregar uma visualização se um uibutton for mantido por x segundos, outro se for mantido por x+y segundos, etc. Encontrei um tutorial. O problema em que estou enfrentando é: como alternar o comprimento do pressionamento do botão? O tutorial mudou o número de torneiras.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count]) 
    {
        case 1: // Single touch
        { 
            // Get the first touch.
            UITouch *touch = [[allTouches allObjects] objectAtIndex:0];

            switch ([touch tapCount])
            {
                case 1: // Single Tap.
                {
                    // Start a timer
                    timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showAlertView:) userInfo:nil repeats:NO];
                    [timer retain];
                } 
                    break;
                case 2: // Double tap.
                    break;
            }
        } 
            break;
        case 2: // Double touch
        {
        } 
            break;
        default:
            break;
    }
}

Alguma sugestão?

Foi útil?

Solução

Eu recebi minha resposta. Acabei de iniciar um NSTIMER em um evento de retoque e parei no toque por dentro.

// TRP - On Touch Down event, start the timer
-(IBAction) startTimer
{
    self.time = 0;
    // TRP - Start a timer
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];

    [timer retain];     // TRP - Retain timer so it is not accidentally deallocated

}

// TRP - Method to update the timer display
-(void)updateTimer
{
    time++;
    NSLog(@"Seconds: %i ", time); 
    if (15 == self.time)
        [timer invalidate];
}

// TRP - On Touch Up Inside event, stop the timer & display results
-(IBAction) btn_MediaMeterResults
{
    [timer invalidate];
    NSLog(@"time: %i ", self.time);

    ResultsViewController *resultsView = [[ResultsViewController alloc] initWithNibName:@"ResultsViewController" bundle:nil];

    // TRP - The following line is passing the "time" variable from MediaMasterViewController to ResultsViewController
    resultsView.time = self.time;

    [self.view addSubview:resultsView.view];
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top