gpt4 book ai didi

ios - 如何使用 5 个以上的 ViewController 为 UITabBarController 中的过渡设置动画?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:30:00 26 4
gpt4 key购买 nike

我有一个 UITabBarController,它有 9 个 View Controller ,我使用前进和后退按钮自定义处理导航。我创建了一个 UIViewControllerAnimatedTransitioning 对象来处理动画(简单的从左到右),它在委托(delegate)方法中返回:

tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning?

但是,在选择第五个索引时和之后,不再调用此函数(因为它现在由 UIMoreNavigationController 处理。是否有动画委托(delegate)或我应该以某种方式处理它UIMoreNavigationController 实例?

最佳答案

您需要指定 moreNavigationController 的委托(delegate)。所以在你的 UITabBarController 类中你需要:

        self.moreNavigationController.delegate = strongDelegate // where strongDelegate is a local instance of MyControllerDelegate as defined below

然后委托(delegate)应该实现 navigationController 函数,该函数将调用适用的 UIViewControllerAnimatedTransitioning 实例:

class MyControllerDelegate: NSObject, UINavigationControllerDelegate {

func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch operation {
case .push:
return MyPresentationAnimationController(isPresenting: true)
case .pop:
return MyPresentationAnimationController(isPresenting: false)
default:
return nil
}
}

您的 animateTransition 函数包含神奇发生的逻辑:

class MyPresentationAnimationController : NSObject, UIViewControllerAnimatedTransitioning {

private let isPresenting: Bool

init(isPresenting: Bool) {
self.isPresenting = isPresenting
}

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return TimeInterval(UINavigationController.hideShowBarDuration)
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard
let toView = transitionContext.view(forKey: .to),
let fromView = transitionContext.view(forKey: .from)
else {
return
}
let containerView = transitionContext.containerView

// TODO: Implement the logic with UIView.animateKeyframes here ...

}

关于ios - 如何使用 5 个以上的 ViewController 为 UITabBarController 中的过渡设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47301613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com