ios - 自定义推送动画打破默认交互式弹出动画

标签 ios objective-c

在我的导航 Controller 委托(delegate)中,我有以下代码:

- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                   animationControllerForOperation:(UINavigationControllerOperation)operation
                                                fromViewController:(UIViewController *)fromVC
                                                  toViewController:(UIViewController *)toVC {
    if ([toVC isKindOfClass:[ParentViewController class]]) {
        if (operation == UINavigationControllerOperationPush) {
            return [(ParentViewController *)toVC pushAnimator];
        }
    }
    return nil;
}

Push animator 实现如下(一些 View Controller 覆盖它以实现自定义转换):
- (id<UIViewControllerAnimatedTransitioning>)pushAnimator {
    return nil;
}

但是在这个默认的交互式弹出动画被破坏之后(但根据文档,如果这个方法返回 nil 默认动画将被使用),即使我没有为选定的 View Controller 使用自定义转换。

如何为某些屏幕带来交互式弹出手势,但使用自定义推送动画?

最佳答案

只需执行UIGestureRecognizerDelegate在 View Controller (或任何实际的东西)上,并做

navigationController?.interactivePopGestureRecognizer?.delegate = self

似乎您甚至不必实现任何东西,但是您可能想尝试类似的东西

func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
    return navigationController?.viewControllers.count ?? 0 > 1
}

关于ios - 自定义推送动画打破默认交互式弹出动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41377270/

相关文章:

ios - 我可以为同时具有 iOS 和 tvOS 目标的项目使用相同的 podfile (cocoapods) 吗?

ios - 使用 Cocoa Pods 导入 Google Analytics iOS SDK 时出错

ios - 仅映射一对多关系的元素

ios - CocoaPods 找不到 pod "braintree_payment": in flutter 的兼容版本

ios - 带图像的推送通知 - iOS - Swift

ios - 在我使用 forin collectionView.visibleCells 将 cell.selected 设置为 NO 后,选择其他它们再次自动选择

Objective-C线程

objective-c - 如何在我的快捷菜单栏应用程序中运行终端命令?

ios - 按位命令产生错误访问错误

iphone - iOS 中 opengl 顶点数据的对齐有多重要