I have a pan gesture recognizer to drag a panel up, down, left, or right. When the direction of the pan is not possible I don't allow the recognizer to begin so that the touches can go to other UI elements within the panel.
However, on iOS7 the translation sometimes gets reset between gestureRecognizerShouldBegin:
and my gesture handler handlePan:
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer*)panGR
{
CGPoint trans = [panGR translationInView:self.view];
NSLog(@"should begin trans: (%.2f, %.2f)", trans.x, trans.y);
...
This logs: should begin trans: (18.00, 0.00)
- (void)handlePan:(UIPanGestureRecognizer*)panGR
{
CGPoint trans = [panGR translationInView:self.view];
switch(panGR.state)
{
case UIGestureRecognizerStateBegan:
NSLog(@"handlePan began trans: (%.2f, %.2f)", trans.x, trans.y);
...
This logs: handlePan began trans: (0.00, 0.00)
Which means the shared code to determine the direction of the pan (right, in this case) works in gestureRecognizerShouldBegin:
and allows the gesture to begin, but then can't be determined in handlePan:
when the state
is UIGestureRecognizerStateBegan
.
Is this a bug in iOS7 or has the behaviour deliberately changed to accommodate new gesture types? Also, can anyone suggest a good way to work around this issue?
gestureRecognizerShouldBegin
and the handler with stateUIGestureRecognizerStateBegan
. I think it's a bug in iOS7 – Taurine