3

How can I detect if my interactivePopGestureRecognizer is completed and will back (pop) to previous view controller or shift is not enough. Then current view controller will back to his normal position.

my code:

if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    [self.interactivePopGestureRecognizer addTarget:self action:@selector(defaultGestureAction:)];
}

- (void)defaultGestureAction:(UIGestureRecognizer *)sender {

   if (sender.state == UIGestureRecognizerStateBegan || sender.state == UIGestureRecognizerStateChanged) {

   } else {

   //this code is fired when I touch up
   //is there any way to check this action (pop or stay)?
   }
}
milczi
  • 7,064
  • 2
  • 27
  • 22

1 Answers1

1

I don't think there is any ready to use flag that says that gesture was positive or negative.

You can try doing that on your own by analyzing translation point and velocity:

- (void)defaultGestureAction:(UIScreenEdgePanGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateEnded)
    {
        CGPoint translatedPoint = [(UIScreenEdgePanGestureRecognizer*) sender translationInView:[sender view]];
        if(translatedPoint.x > self.view.bounds.size.width * 0.5f || [sender velocityInView:self.view].x > 500.0f)
        {
            //did trigger translation
        }
        else
        {
            //did cancel translation
        }
    }
}
Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71