gpt4 book ai didi

swift - 为什么我的自定义转换不适用于我的导航 Controller ?

转载 作者:行者123 更新时间:2023-11-30 11:09:53 26 4
gpt4 key购买 nike

我在代码中使用协调器模式从 RootNavigationController 转换到 SplashScreenViewController

class AppCoordinator {
let window: UIWindow
let rootViewController: RootNavigationController

init(window: UIWindow) {
self.window = window
rootViewController = RootNavigationController()
let splashScreenViewController = SplashScreenViewController()

rootViewController.pushViewController(splashScreenViewController, animated: false)
}
}
extension AppCoordinator: Coordinator {
func start() {
window.rootViewController = rootViewController
window.makeKeyAndVisible()
}
}

我还使用自定义转换来处理从 RootNavigationController 到 SplashScreenNavigationController 的转换。

class FadeInAnimator: NSObject {
var duration: TimeInterval = 1.0
}
extension FadeInAnimator: UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView

guard let toViewController = transitionContext.viewController(forKey: .to) else { return }

containerView.addSubview(toViewController.view)
toViewController.view.alpha = 0

let durationOfTransition = transitionDuration(using: transitionContext)
UIView.animate(withDuration: durationOfTransition, delay: 0, options: [.curveEaseIn], animations: {
toViewController.view.alpha = 1
}) { (finished) in
transitionContext.completeTransition(finished)
}
}
}

我已将 RootNavigationController 的委托(delegate)设置为其自身并实现了动画转换,但是,当我启动应用程序时,它似乎忽略了我所做的一切,仅使用系统默认转换。

这是 RootNavigationController 中的代码

class RootNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
extension RootNavigationController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch operation {
case .push: return FadeInAnimator()
case .pop: return nil
case .none: return nil
}
}
}

最佳答案

删除打开和关闭括号

UIView.animate(withDuration: durationOfTransition, delay: 0, options: .curveEaseIn, animations: 

关于swift - 为什么我的自定义转换不适用于我的导航 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52291432/

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