У меня vc1, представляющий контроллер навигации, содержащий vc2. Переход между vc1 и контроллером навигации - «Present Modally», vc2 отображается со стандартной анимацией снизу вверх.
Я хочу представить vc2, встроенный в контроллер навигации, из vc1 с настраиваемой анимацией перехода.
я пробовал
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()
//...
}
А потом:
(1) Установите transitioningDelegate для vc2. Очевидно никакого эффекта.
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) Подкласс UINavigationController и установите его transitioningDelegate. vc2 появляется нужным образом, но панель навигации исчезла, и следующий контроллер представления после vc2 не появляется в сегменте «Показать».
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let controller = segue.destination as? Vc2NavigationController {
controller.transitioningDelegate = controller.customTranstionDelegate
}
}
Как я могу представить vc2, встроенный в контроллер навигации, из vc1 с настраиваемой анимацией перехода?