【问题标题】:System interactive pop gesture broken in UINavigationController when providing a custom animation controller提供自定义动画控制器时,UINavigationController 中的系统交互弹出手势中断
【发布时间】:2019-11-30 17:14:02
【问题描述】:

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

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 时,系统管理的交互式返回手势不再起作用。与系统动画相关的所有其他内容仍然有效。

我尝试将交互式弹出手势的委托设置为我的自定义导航控制器,并从一些成功程度不同的方法返回真/假。

【问题讨论】:

    标签: ios swift uinavigationcontroller uikit


    【解决方案1】:

    所以这似乎是 UIKit 中的一个错误。我创建了一个重现错误并将其提交给 Apple 的小项目。本质上,只要animationController 委托方法由UINavigationControllerDelegate 实现,交互式弹出手势就会中断。作为一种解决方法,我创建了两个委托代理,一个实现该方法,一个不实现:

    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 的状态,我只是在充当实际UINavigationControllerDelegate 的这些类之间交替。

    【讨论】:

      猜你喜欢
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多