Question

Travailler avec XCode 4.2 et en essayant de se familiariser avec les UIGestureRecognisers. Tout semble aller assez bien jusqu'à présent, mais je suis encore avoir quelques problèmes.

Quand j'utilisais geste les dispositifs de reconnaissance de Swipe, tout allait bien, il reconnaîtrait swipes dans toutes les directions différentes et ferait en permanence. Mon problème est maintenant, lorsque vous utilisez le geste pan recogniser, il reconnaît la première amende swipe pan, mais refuse simplement d'accepter d'autres gestes. Je peux donc déplacer des éléments environ une fois au besoin, mais après cela, ne peux rien faire.

Je mis mon geste comme suit:

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

Alors ceci est ma méthode « panBody » qui manipule tous:

- (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");
    }
}
}

bodypanels, Toppanel et SidePanel sont IBOutlets liés à UIView s'overlays en haut de mon interface .xib

Si quelqu'un pouvait faire la lumière sur ces informations, ce serait génial parce que je ne sais absolument pas ce qui se passe !!

Merci,

Matt

Était-ce utile?

La solution

D'abord, je voudrais vérifier que

if (recognizer.state == UIGestureRecognizerStateChanged)

avant de faire vos traductions (il y a beaucoup d'autres états possibles qui ne vous justifier toute action). Aussi je réinitialiser la traduction à chaque rappel étant donné que vous les accumulez en utilisant la méthode UIPanGestureRecognizer

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

Si le geste de reconnaissance cesse, il pourrait être qu'un autre geste de reconnaissance interfère avec elle. Avez-vous encore là un UISwipeGestureRecognizer actif? Si oui, vous devez désactiver probablement l'un d'entre eux. Vous pouvez également consulter cette méthode

- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer

qui vous permet de spécifier quels devraient être la priorité de reconnaissance donnée.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top