获得interactivePopGestureRecognizerclosurescallback/事件
是否有一个干净的解决scheme,让视图控制器上的callback或事件被interactivePopGestureRecognizer
解散(popup)?
为了清楚起见,我需要一些明确的方法在控制器被这个手势识别器popup之前在最上面的控制器(而不是其他的)上被调用。 我不想在导航控制器上得到事件,并将事件发送到适当的控制器,我不想使用viewWillAppear
或viewWillDissapear
…
我最近的事情是添加一个目标/select器对只有两个问题的手势。 首先我不能得到直接的信息,如果控制器将被解雇或不( UIGestureRecognizerStateEnded
将在任何情况下触发)。 第二个控制器被解散后,我需要从识别器中删除目标。
原因是我有几个控制器需要发送一些信息给他们的代表。 通过“完成”和“取消”button事件被触发,委托方法被调用,然后控制器被popup。 我需要几乎相同的代码尽可能less的变化发生。
这种手势的另一种情况是抛出警报视图和恢复操作的可能性:当这个手势结束时,是否有一种显示警报视图的方式,问“你确定要取消你的工作”,并让用户select是否控制器将被popup或取回。
我知道这是古老的,但对于任何可能面临类似问题的人。 这是我使用的方法。 首先我注册一个UINavigationControllerDelegate
到我的导航控制器。 代表需要执行。
Objective-C的
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
迅速
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool)
所以实现看起来像这样。
Objective-C的
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { id<UIViewControllerTransitionCoordinator> tc = navigationController.topViewController.transitionCoordinator; [tc notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) { NSLog(@"Is cancelled: %i", [context isCancelled]); }]; }
迅速
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) { if let coordinator = navigationController.topViewController?.transitionCoordinator() { coordinator.notifyWhenInteractionEndsUsingBlock({ (context) in print("Is cancelled: \(context.isCancelled())") }) } }
当用户抬起手指并且( [context isCancelled];
-C) [context isCancelled];
时,callback将被触发[context isCancelled];
(Swift) context.isCancelled()
将返回YES
/ true
如果animation颠倒(视图控制器没有popup),否则NO
/ false
。 在context
中有更多的东西可以使用,比如所涉及的视图控制器和发布后完成的animation的百分比等。