Position adjustment with interactivePopGestureRecognizer

I have a custom control that contains a series of buttons that mimic a tab bar. This control goes out of view when the UINavigationController moves away from the root view controller and goes back when moving to the root.

IOS 7 has a UIScreenEdgePanGestureRecognizer which gives a swipe gesture from swipe to go. In this way, I modify my user control so that the slide amount matches the translation of UIScreenEdgePanGestureRecognizer .

The problem is that when the user releases the touch screen, how can I determine if the UINavigationController move backward or return to its original state?

 [self.interactivePopGestureRecognizer addTarget:self action:@selector(panningBack:)]; - (void) panningBack:(UIPanGestureRecognizer *)recognizer { // Snipped - Code that reads the recognizer translation and adjust custom control y position if (recognizer.state == UIGestureRecognizerStateEnded) { // Question: Does it go back, or does it not? // If it goes back, slide custom control into view // Else slide custom control out of view } } 
+4
source share
2 answers

I know this is a pretty old question, so the answer may not be useful for the OP, but maybe for someone else. Yesterday I ran into the same problem and searched many times for SO, the rest of the network, finding nothing. So, here is the solution I used for a similar problem. This is implemented as a delegate to the navigation manager, but I think you can do it elsewhere if that is better.

  - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { id<UIViewControllerTransitionCoordinator> tc = navigationController.topViewController.transitionCoordinator; [tc notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) { NSLog(@"DONE!!!"); NSLog(@"Container View: %@", [context containerView]); NSLog(@"From VC: %@", [context viewControllerForKey:UITransitionContextFromViewControllerKey]); NSLog(@"To VC: %@", [context viewControllerForKey:UITransitionContextToViewControllerKey]); NSLog(@"Initially Interactive: %i", [context initiallyInteractive]); NSLog(@"Completion Curve: %d", [context completionCurve]); NSLog(@"Is Animated: %i", [context isAnimated]); NSLog(@"Is Cancelled: %i", [context isCancelled]); NSLog(@"Is Interactive: %i", [context isInteractive]); NSLog(@"Percent Complete: %f", [context percentComplete]); NSLog(@"Presentation Style: %d", [context presentationStyle]); NSLog(@"Transition Duration: %f", [context transitionDuration]); }]; } 

This works when the user lifts his finger and the animation is canceled or completed. [context isCancelled]; will inform you whether it will be canceled or supplemented. In addition, there is a lot of other nice information in the context object that you can use.

+4
source

I would say that the easiest solution is to use the default gestures implemented in the navigation controller. When the view appears, display the panel and hide the panel when it disappears.

An elegant solution in order to know whether it should return or not, would be to detect the last movement.

Value if the user has moved a few pixels to the left, and releases → a rebound back if the user has moved several pixels to the right and released → show the previous controller

This can be done if you save the location in the changed state and compare it with the completed state.

Getting this point:

Point CGPoint = [Recognizer locationInView: view];

+1
source

All Articles