首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提供自定义动画控制器时在UINavigationController中中断的系统交互pop手势

提供自定义动画控制器时在UINavigationController中中断的系统交互pop手势
EN

Stack Overflow用户
提问于 2019-11-30 17:14:02
回答 1查看 136关注 0票数 0

我有一个自定义的UINavigationController子类,它将自己设置为UINavigationControllerDelegate,并有条件地返回自定义动画器。我希望能够使用布尔标志在自定义动画器和系统动画之间切换。我的代码如下所示:

代码语言:javascript
复制
class CustomNavigationController: UINavigationControllerDelegate {

    var useCustomAnimation = false
    private let customAnimator = CustomAnimator()

    func navigationController(_ navigationController: UINavigationController,
                              animationControllerFor operation: UINavigationController.Operation,
                              from fromVC: UIViewController,
                              to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        if useCustomAnimation {
            return CustomAnimator()
        }
        return nil
    }
}

但是,当useCustomAnimationfalse时,系统管理的交互式回动作不再工作。与系统动画相关的所有其他内容仍然有效。

我尝试将交互式pop手势的委托设置为我的自定义导航控制器,并从一些成功级别不同的方法返回true/false。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-30 17:14:02

因此,这似乎是UIKit中的一个bug。我创建了一个小项目来复制错误并将其提交给Apple。实际上,每当animationController委托方法由UINavigationControllerDelegate实现时,交互式pop手势就会中断。作为解决办法,我创建了两个委托代理,一个实现该方法,另一个没有:

代码语言:javascript
复制
class NavigationControllerDelegateProxy: NSObject, UINavigationControllerDelegate {

    weak var delegateProxy: UINavigationControllerDelegate?

    init(delegateProxy: UINavigationControllerDelegate) {
        self.delegateProxy = delegateProxy
    }

    /*
    ... Other Delegate Methods
    */
}

class CustomAnimationNavigationControllerDelegateProxy: NavigationControllerDelegateProxy {

    func navigationController(_ navigationController: UINavigationController,
                              animationControllerFor operation: UINavigationController.Operation,
                              from fromVC: UIViewController,
                              to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return delegateProxy?.navigationController?(navigationController,
                                                    animationControllerFor: operation,
                                                    from: fromVC,
                                                    to: toVC)
    }
}

我只是在这些类之间交替使用,根据useCustomAnimation的状态作为实际的useCustomAnimation

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59118446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档