Pregunta

Estaba jugando con el SDK y me preguntaba si es posible que un evento UITouch pueda funcionar dentro de un UIScrollView.

He configurado un UIScrollView que maneja una UIView grande, dentro de UIView hay un UIImageView, logré que UITouch arrastre UIImageView fuera de UIScrollView pero dentro no registra el evento.

Supongo que lo que estaba tratando de lograr era arrastrar UIImageView alrededor de la UIView grande mientras UIScrollView se mueve a lo largo de la imagen si el usuario la arrastra más allá del POS de cuando UIView comenzó a arrastrarse, si eso tiene sentido.

Muchas gracias

¿Fue útil?

Solución

(Si entendí bien la pregunta)

Intercepciones UIScrollView touchMoved eventos y no los propaga a su contenido si el desplazamiento está habilitado.Entonces, para arrastrar el contenido de UIScrollView en mi aplicación, hice el siguiente truco:

toquesComenzó: Comprueba si tocas la región "arrastrable".En caso afirmativo, deshabilite el desplazamiento en UIScrollView.

tocaMovido: Ahora, como el desplazamiento está deshabilitado, su vista de contenido recibe este evento y puede mover su UIImageView arrastrable en consecuencia.

toquesFinalizado: Vuelva a habilitar el desplazamiento en UIScrolliew.

Si desea arrastrar la vista fuera del área visible de UIScrollView, es posible que también deba verificar manualmente si está cerca de los límites y ajustar manualmente el desplazamiento del contenido (no lo intenté yo mismo, pero creo que debería funcionar).

Otros consejos

La mejor manera de poner en práctica esta que encontré fue una subclase de la clase UIScrollView sí y luego añadir los toques comenzaron método de evento en el que su subclase. Esto funcionó para mí.

(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];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top