与interactivePopGestureRecognizer一起调整位置

Jeo*_*uan 4 iphone objective-c uinavigationcontroller ios ios7

我有一个自定义控件,包含一行按钮,模仿标签栏.当UINavigationController导航离开根视图控制器时,此控件滑出视图,并在导航到根时滑回.

使用iOS 7,UIScreenEdgePanGestureRecognizer可以实现向后滑动的手势.我正在修改我的自定义控件,以便幻灯片数量对应于UIScreenEdgePanGestureRecognizer翻译.

问题是,当用户释放触摸时,我该如何判断它是否UINavigationController会导航或弹回原始视图?

[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
    }
}
Run Code Online (Sandbox Code Playgroud)

Pet*_*lom 5

我知道这是一个相当古老的问题所以答案可能不会对OP有用,但可能对其他人有用.我昨天遇到了同样的问题,并在没有真正找到任何东西的情况下在网上的其余部分进行了大量搜索.所以这是我用于类似问题的解决方案.这是在navigationcontroller委托中实现的,但我想如果能更好地满足您的需求,您可以在其他地方执行此操作.

    - (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]);
    }];
}
Run Code Online (Sandbox Code Playgroud)

当用户抬起手指并且动画相反或完成时,这将触发.该[context isCancelled];会告诉你,如果它扭转或完成.并且在上下文对象中还有许多其他可以使用的好信息.