4

我有一个自定义控件,包含一排按钮,模仿标签栏。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
    }
}
4

2 回答 2

5

I know this is a rather old question so the answer might not be of use to the OP but maybe to some one else. I faced the same problem yesterday and did a lot of searching on SO an the rest of the web without really finding anything. So here is the solution I used for a similar problem. This is implemented in the navigationcontroller delegate but i guess you can do it some other place if that fits your need 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 will fire when user lift her finger and the animation is rather reversed or completed. The [context isCancelled]; will tell you if it reversed or completer. And there is also a lot of other nice info in the context object that can be to use.

于 2014-01-16T07:51:17.463 回答
1

我想说最简单的解决方案是使用导航控制器中实现的默认手势。当视图出现时显示栏并在栏消失时隐藏栏。

知道它是否应该返回的一个优雅的解决方案是检测最后一个动作。

意思是如果用户向左移动一些像素并释放 -> 如果用户向右移动一些像素并释放 -> 弹回 -> 显示上一个控制器

如果您将位置保存为状态更改并将其与状态结束进行比较,则可以完成此操作。

得到这样的观点:

CGPoint 点 = [识别器 locationInView:view];

于 2013-10-23T20:55:31.947 回答