Problemi con UIPanGestureRecogniser
-
25-10-2019 - |
Domanda
Lavorare con XCode 4.2 e cercando di fare i conti con le UIGestureRecognisers. Tutto sembra andare abbastanza bene finora, ma sto ancora avendo alcuni problemi.
Quando ero con i riconoscitori gesto di scorrimento, tutto andava bene, che avrebbe riconosciuto fendenti in tutte le direzioni diverse e avrebbe fatto in modo continuo. Il mio problema ora è, quando si utilizza il riconoscitore gesto padella, riconosce il primo bel colpo pan, ma poi si rifiuta semplicemente di accettare eventuali ulteriori gesti. Così posso spostare gli elementi circa una volta a seconda delle necessità, ma dopo che, non posso far nulla.
Ho impostato il mio gesto come segue:
UIPanGestureRecognizer *panBody = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panBody:)];
[bodyGestureView addGestureRecognizer:panBody];
Allora questo è il mio metodo 'panBody' che gestisce tutto:
- (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 e pannello laterale sono IBOutlets legate al UIView ha sovrapposto nella parte superiore della mia interfaccia .xib
Se qualcuno potesse far luce su queste informazioni, che sarebbe grande causa non ho assolutamente idea di cosa sta succedendo !!
Grazie,
Matt
Soluzione
Per prima cosa vorrei verificare che
if (recognizer.state == UIGestureRecognizerStateChanged)
prima di fare le vostre traduzioni (ci sono molti altri stati possibili, che non giustificherebbero si intraprendere qualsiasi azione). Inoltre vorrei ripristinare la traduzione ad ogni richiamo dato che si sta accumulando loro utilizzando il metodo UIPanGestureRecognizer
- (void)setTranslation:(CGPoint)translation inView:(UIView *)view
Se il sistema di riconoscimento gesto si ferma potrebbe essere che un altro sistema di riconoscimento gesto interferisce con esso. Hai ancora un UISwipeGestureRecognizer attiva lì? Se è così probabilmente si dovrebbe disattivare uno di loro. Si può anche guardare a questo metodo
- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer
che consente di specificare quali riconoscitore dovrebbe essere data la priorità.