我有一个自定义控件,包含一行按钮,模仿标签栏。此控件在 UINavigationController
离开 Root View Controller 时滑出 View ,并在导航到 Root View Controller 时滑回。
在 iOS 7 中,UIScreenEdgePanGestureRecognizer
提供了滑动返回手势。因此,我正在修改我的自定义控件,以便滑动量对应于 UIScreenEdgePanGestureRecognizer
的翻译。
问题是,当用户释放触摸时,我如何判断 UINavigationController
将导航回或弹回原始 View ?
[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
}
}
最佳答案
我知道这是一个相当古老的问题,所以答案可能对 OP 没有用,但可能对其他人有用。我昨天遇到了同样的问题,并且在 SO 和网络的其余部分进行了大量搜索,但没有真正找到任何东西。 所以这是我用于类似问题的解决方案。这是在 navigationcontroller 委托(delegate)中实现的,但我想如果更适合您的需要,您可以在其他地方进行。
- (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]);
}];
}
当用户抬起她的手指并且动画相当反转或完成时,这将触发。 [context isCancelled];
会告诉你它是反转的还是完成的。上下文对象中还有许多其他有用的信息可供使用。
关于iphone - 与 interactivePopGestureRecognizer 一起调整位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19024407/