I have vc1, which is presenting navigation controller, which contains vc2. The segue between vc1 and navigation controller is "Present Modally", vc2 appears with standard animation, from the bottom to the top.
I want to present vc2, embedded in navigation controller, from vc1 with custom transition animation.
I've tried
class CustomAnimator: NSObject {
func animationDuration() -> TimeInterval {
return 1.0
}
fileprivate func animateCustomTransition(using transitionContext: UIViewControllerContextTransitioning) {
// ...
}
}
extension CustomAnimator: UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return animationDuration()
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
animateCustomTransition(using: transitionContext)
}
}
class CustomTransitionDelegate: NSObject {
let animator: CustomAnimator
override init() {
animator = CustomAnimator()
super.init()
}
}
extension CustomTransitionDelegate: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self.animator
}
}
class Vc2ViewController: UIViewController {
// ...
var customTranstionDelegate = CustomTransitionDelegate()
//...
}
And then:
(1) Set transitioningDelegate of vc2. Obviously no effect.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let navController = segue.destination as? UINavigationController {
if let controller = navController.viewControllers.first as? Vc2ViewController {
controller.transitioningDelegate = controller.customTranstionDelegate
}
}
}
(2) Subclass UINavigationController and set it's transitioningDelegate. vc2 appears in the needed way, but navigation bar has disappeared and next view controller after vc2 doesn't appear on "Show" segue.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let controller = segue.destination as? Vc2NavigationController {
controller.transitioningDelegate = controller.customTranstionDelegate
}
}
How can i present vc2, embedded in navigation controller, from vc1 with custom transition animation?