Pregunta

Trabajar con Xcode 4.2 y tratando de controlar con los UigestureRisersers. Todo parece ir bastante bien hasta ahora, pero todavía estoy teniendo algunos problemas.

Cuando estaba usando los reconocedores de gestos deslizantes, todo estaba bien, reconocería golpes en todas las direcciones diferentes y lo haría continuamente. Mi problema ahora es que, cuando se usa el reconocimiento de gestos de la sartén, reconoce el primer sartén de la bandeja, pero luego se niega a aceptar más gestos. Entonces puedo mover elementos una vez según sea necesario, pero después de eso, no puedo hacer nada.

Establecí mi gesto de la siguiente manera:

UIPanGestureRecognizer *panBody = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panBody:)];
[bodyGestureView addGestureRecognizer:panBody];

Entonces este es mi método 'PanBody' que lo maneja todo:

- (void)panBody:(UIPanGestureRecognizer *)recognizer
{
CGPoint translate = [recognizer translationInView:self.view];

CGRect bodyPanelFrame = bodyPanel.frame;
bodyPanelFrame.origin.x += translate.x;
bodyPanelFrame.origin.y += translate.y;
recognizer.view.frame = bodyPanelFrame;

CGRect topPanelFrame = topPanel.frame;
topPanelFrame.origin.x += translate.x;
topPanelFrame.origin.y += translate.y;
recognizer.view.frame = topPanelFrame;

CGRect sidePanelFrame = sidePanel.frame;
sidePanelFrame.origin.x += translate.x;
sidePanelFrame.origin.y += translate.y;
recognizer.view.frame = sidePanelFrame;

NSLog(@"Panning");

if (recognizer.state == UIGestureRecognizerStateEnded)
{
    bodyPanel.frame = bodyPanelFrame;

    if((topPanel.frame.origin.x + translate.x) <= 193)
    {
        topPanel.frame = CGRectMake(topPanelFrame.origin.x, topPanel.frame.origin.y, topPanel.frame.size.width, topPanel.frame.size.height);
    }
    else
    {
        topPanel.frame = CGRectMake(193, 0, topPanel.frame.size.width, topPanel.frame.size.height);
        NSLog(@"Top panel not in frame");
    }

    if((sidePanel.frame.origin.y + translate.y) < 57)
    {
        sidePanel.frame = CGRectMake(sidePanel.frame.origin.x, sidePanelFrame.origin.y, sidePanel.frame.size.width, sidePanel.frame.size.height);
    }
    else
    {
        sidePanel.frame = CGRectMake(0, 56, sidePanel.frame.size.width, sidePanel.frame.size.height);
        NSLog(@"Side panel not in frame");
    }
}
}

BodyPanel, Toppanel y SidePanel son Iboutlets vinculados a Uiview superpuestos en la parte superior de mi interfaz .xib

Si alguien pudiera arrojar cualquier luz sobre esta información, ¡sería una gran porque no tengo ni idea de lo que está pasando!

Gracias,

Mate

¿Fue útil?

Solución

Primero comprobaría eso

if (recognizer.state == UIGestureRecognizerStateChanged)

Antes de hacer sus traducciones (hay muchos otros estados posibles que no lo justificarían tomando ninguna acción). También restablecería la traducción en cada devolución de llamada dado que los está acumulando usando el método UIPangeStereCognizer

- (void)setTranslation:(CGPoint)translation inView:(UIView *)view

Si el reconocimiento de gestos se detiene, podría ser que otro reconocimiento de gestos esté interfiriendo con él. ¿Todavía tiene un UISWIPEGESTURACE ACTIVO activo allí? Si es así, probablemente debería desactivar uno de ellos. También puedes mirar este método

- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer

lo que le permite especificar qué reconocimiento se le debe dar prioridad.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top