如何在animationController(UIViewControllerTransitioningDelegate)中使用源(不呈现)?
我正在制作一个自定义过渡管理器。它符合协议 UIViewControllerAnimatedTransitioning
& UIViewControllerTransitioningDelegate
。
当presenting
从RocketsVC
到RocketDetailsVC
时,func被称为animationController(for Presentedpresented: UIViewController,presenting:UIViewController,source:UIViewController )
,以下类型被传递到那里:
presented
:RocketDetailsViewController
presenting
:MainTabBarController
(错误在这里)source
:RocketsViewController
这个函数在 TransitionManager.swift
中声明:
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
type = .presentation
return self // TransitionManager
}
然后 animateTransition
方法被调用...
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromViewController = transitionContext.viewController(forKey: .from) as? TransitionManagerProtocol,
let toViewController = transitionContext.viewController(forKey: .to) as? TransitionManagerProtocol
...效果为零,因为 MainTabBarController
不符合 TransitionManagerProtocol
。
如果我构建一个没有 MainTabBarController
的项目(rootVC 是 RocketsVC),那么一切都会按预期进行。
我应该怎么做才能使转换工作?我在 MainTabBarController
上犯了罪,但也许有一种方法可以以某种方式传递给 animationController
方法source
而不是 presenting
?
TransitionManager.swift
RocketsViewController.swift
MainTabBarController.swift
I'm making a custom Transition Manager. It conforms to the protocols UIViewControllerAnimatedTransitioning
& UIViewControllerTransitioningDelegate
.
When present
ing from RocketsVC
to RocketDetailsVC
, func is called animationController(for Presented presented: UIViewController, presenting: UIViewController, source: UIViewController)
, the following types are passed there:
presented
:RocketDetailsViewController
presenting
:MainTabBarController
(Error is here)source
:RocketsViewController
This functions are declared in TransitionManager.swift
:
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
type = .presentation
return self // TransitionManager
}
And then animateTransition
method is called...
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromViewController = transitionContext.viewController(forKey: .from) as? TransitionManagerProtocol,
let toViewController = transitionContext.viewController(forKey: .to) as? TransitionManagerProtocol
...with zero effect, because MainTabBarController
does not conform to TransitionManagerProtocol
.
If I build a project without MainTabBarController
(rootVC is RocketsVC), then everything works as it should.
What should I do to make the transition work? I'm sinning on MainTabBarController
, but maybe there is a way to somehow pass to animationController
method source
instead of presenting
?
TransitionManager.swift
RocketsViewController.swift
MainTabBarController.swift
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我花了很长时间找到的解决方案:
并且:
The solution I've found after long hours:
And: