HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 获取interactivePopGestureRecognizer关闭回调/事件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_419_0@
是否有一个干净的解决方案来获取一个回调或事件在视图控制器被关闭(弹出)由interactivePopGestureRecognizer?

要清楚,我需要一些明确的方法,在控制器将被这个手势识别器弹出之前,在最上面的控制器(而不是其他)上被调用.我不想在导航控制器上获取事件,并将事件发送到相应的控制器,我不想使用viewWillAppear或viewWillDissapear …

我最近的事情是添加一个目标/选择对对手势只有2个问题.首先,如果控制器被关闭,UGestureRecognizerStateEnded将在任何情况下都会触发,我无法得到直接信息.在控制器被关闭之后,我需要从识别器中删除目标.

原因是我有几个控制器需要向他们的代表发送一些信息.通过“完成”和“取消”按钮触发事件,委托方法调用,然后弹出控制器.我需要几乎相同的情况发生,尽可能少的更改代码.

这种手势的另一种情况是投掷警报视图和恢复动作的可能性:当这个手势结束询问时,是否有一种显示警报视图的方法,如“你确定要取消你的工作”,并让用户选择控制器将被弹出或带回来.

@L_944_21@

我知道这是老旧的,但对于可能面临类似问题的任何人来说这是我使用的方法.首先我将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,animated: Bool) {
    if let coordinator = navigationController.topViewController?.transitionCoordinator() {
        coordinator.notifyWhenInteractionEndsUsingBlock({ (context) in
            print("Is cancelled: \(context.isCancelled())")
        })
    }
}

用户抬起手指和(Objec-C)[context isCancelled]时,回调将触发; (Swift)context.isCancelled()将返回YES / true,如果动画被反转(视图控制器没有弹出),否则为NO / false.在上下文中有更多的东西可以被使用,就像两个视图控制器相关的,以及在发布时完成的动画的百分比.

大佬总结

以上是大佬教程为你收集整理的ios – 获取interactivePopGestureRecognizer关闭回调/事件全部内容,希望文章能够帮你解决ios – 获取interactivePopGestureRecognizer关闭回调/事件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。