gpt4 book ai didi

ios - 如何在自定义 navigationController 代码中定位特定的 viewController?

转载 作者:行者123 更新时间:2023-11-29 01:38:57 25 4
gpt4 key购买 nike

我有这个要实现的自定义 navigationController 动画,但我希望仅当特定的 viewController 在堆栈上时才实现代码。这是代码:

class ARNImageTransitionNavigationController: UINavigationController, UINavigationControllerDelegate {

weak var interactiveAnimator : ARNTransitionAnimator?
var currentOperation : UINavigationControllerOperation = .None

override func viewDidLoad() {
super.viewDidLoad()

self.interactivePopGestureRecognizer?.enabled = false
self.delegate = self
}

func navigationController(navigationController: UINavigationController,
animationControllerForOperation operation: UINavigationControllerOperation,
fromViewController fromVC: UIViewController,
toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning?
{
self.currentOperation = operation

if let _interactiveAnimator = self.interactiveAnimator {
return _interactiveAnimator
}

if operation == .Push {
return ARNImageZoomTransition.createAnimator(.Push, fromVC: fromVC, toVC: toVC)
} else if operation == .Pop {
return ARNImageZoomTransition.createAnimator(.Pop, fromVC: fromVC, toVC: toVC)
}

return nil
}

func navigationController(navigationController: UINavigationController, interactionControllerForAnimationController animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
if let _interactiveAnimator = self.interactiveAnimator {
if self.currentOperation == .Pop {
return _interactiveAnimator
}
}
return nil
}
}

现在我应该向此代码添加什么,以确保它实现其所有方法,但仅当特定的 viewController 位于堆栈上时?

最佳答案

如果您已经为有问题的 View Controller 提供了单独的 swift 类,那么您可以检查它们的文件类名。假设你在插入时想要这个动画,例如ProfilePageViewController导航堆栈,然后使用 if operation == .Push && toVC.isKindOfClass(ProfilePageViewController) 。我在您提供的代码示例中添加了剩余的代码。

func navigationController(navigationController: UINavigationController,
animationControllerForOperation operation: UINavigationControllerOperation,
fromViewController fromVC: UIViewController,
toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning?
{
self.currentOperation = operation

if let _interactiveAnimator = self.interactiveAnimator {
return _interactiveAnimator
}

if operation == .Push && toVC.isKindOfClass(swiftNameofVCClassFile) {
return ARNImageZoomTransition.createAnimator(.Push, fromVC: fromVC, toVC: toVC)
} else if operation == .Pop && fromVC.isKindOfClass(swiftNameofVCClassFile) {
return ARNImageZoomTransition.createAnimator(.Pop, fromVC: fromVC, toVC: toVC)
}

return nil
}

关于ios - 如何在自定义 navigationController 代码中定位特定的 viewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32645881/

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