I did a custom transition between ViewControllerA and ViewControllerB. But the fromVc type is not ViewControllerA. (I debug found it is a Tab Controller)
I want the fromVC to be ViewControllerA, or I can get ViewControllerA somehow. (I also use transitionContext.viewController(forKey: .from)?.children.last or first, still not working)
In ViewControllerA:
extension ViewControllerA: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController,
presenting: UIViewController,
source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if presented is ViewControllerB {
return Animator()
}
return nil
}
// here is how I present ViewControllerB in ViewControllerA's viewModel
let vcB = ViewControllerB()
vcB.transitioningDelegate = delegate
vcB.modalPresentationStyle = .custom
self.delegate.present(vcB, animated: true, completion: nil)
in ViewControllerB: nothing special
in Aminator
public class Animator: NSObject, UIViewControllerAnimatedTransitioning {
public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 3
}
public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
// I need to do some staff in ViewControllerA so that I need to get fromVc.
guard
fromVc = transitionContext.viewController(forKey: .from)? as ViewControllerA,
toVc = transtionContext.viewController(forKEy: .to)? as ViewControllerB else {return}
// do some animation in CATransaction and settransitionContext.completeTransition(true)
// ....
}
}