ios - 提供自定义动画控制器时,UINavigationController 中的系统交互弹出手势中断
问题描述
我有一个自定义子类,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
is时false
,系统管理的交互式返回手势不再起作用。与系统动画相关的所有其他内容仍然有效。
我尝试将交互式弹出手势的委托设置为我的自定义导航控制器,并从某些成功程度不同的方法返回真/假。
解决方案
所以这似乎是 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)
}
}
我只是UINavigationControllerDelegate
根据useCustomAnimation
.
推荐阅读
- java - 为什么我的单向 @ManyToOne 关系中的表没有加入 Spring Data findAll() 查询?
- r - 遍历嵌套数据框并在 RMarkdown 中打印 kables
- asp.net-core-2.0 - 登录后 ASP.NET MVC Core 3.0 在浏览器后退按钮单击时再次显示登录页面
- php - 将身份验证扩展到使用不同 php 框架的子文件夹
- android - 安全的 sqlite 数据库:Android
- android - 颤振折叠容器
- excel - Excel 中的 VBA 代码在工作表中的激活事件上运行缓慢。需要提高性能请
- laravel - 在 Laravel 6 中使用数组传递数据?
- postgresql - 如何按日期分组?
- angular - Ionic 4 npm run build --prod 在 Apache 服务器上托管时不起作用