UIScrollView obtener eventos táctiles


¿Cómo puedo detectar puntos de contacto en mi UIScrollView? Los métodos touchs delegate no funcionan.

Author: Josh Caswell, 2011-03-07

3 answers

Configurar un reconocedor de gestos tap:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];    

Y obtendrás los toques en:

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{ 
    CGPoint touchPoint=[gesture locationInView:scrollView];
}
 180
Author: Suresh.D,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-19 18:59:51

Puede crear su propia subclase UIScrollView y luego puede implementar lo siguiente:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

{

NSLog(@"DEBUG: Touches began" );

UITouch *touch = [[event allTouches] anyObject];

    [super touchesBegan:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {

    NSLog(@"DEBUG: Touches cancelled");

    // Will be called if something happens - like the phone rings

    UITouch *touch = [[event allTouches] anyObject];

    [super touchesCancelled:touches withEvent:event];

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    NSLog(@"DEBUG: Touches moved" );

    UITouch *touch = [[event allTouches] anyObject];

    [super touchesMoved:touches withEvent:event];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"DEBUG: Touches ending" );
    //Get all the touches.
    NSSet *allTouches = [event allTouches];

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

            switch([touch tapCount])
            {
                case 1://Single tap

                    break;
                case 2://Double tap.

                    break;
            }
        }
            break;
    }
    [super touchesEnded:touches withEvent:event];
}
 6
Author: Vicky,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-05-15 22:17:35

Si estamos hablando de los puntos dentro de scrollview entonces puedes engancharte con el método delegado:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

Y dentro del método, lea la propiedad:

@property(nonatomic) CGPoint contentOffset

Desde el ScrollView para obtener la coordinación.

 1
Author: Nevin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-03-07 06:12:39