我有一个自定义的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
}
}但是,当useCustomAnimation是false时,系统管理的交互式回动作不再工作。与系统动画相关的所有其他内容仍然有效。
我尝试将交互式pop手势的委托设置为我的自定义导航控制器,并从一些成功级别不同的方法返回true/false。
发布于 2019-11-30 17:14:02
因此,这似乎是UIKit中的一个bug。我创建了一个小项目来复制错误并将其提交给Apple。实际上,每当animationController委托方法由UINavigationControllerDelegate实现时,交互式pop手势就会中断。作为解决办法,我创建了两个委托代理,一个实现该方法,另一个没有:
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。
https://stackoverflow.com/questions/59118446
复制相似问题