Member-only story
Customize your navigation with Push using the present animation in iOS
Purpose
Implement a custom navigation animation that uses a “present-like” animation effect during push and pop operations across multiple view controllers.
- A pushes B (normal animation)
- B pushes C (custom present-like animation)
- C pops back to B (custom dismiss-like animation)
- Multiple view controllers may push to C, all using the same custom animations
Steps
Step 1: Create Custom Animation Controllers
- PresentAnimationController: Handles the animation effect when pushing to ViewControllerC.
- DismissAnimationController: Handles the animation effect when popping back from ViewControllerC.
import Foundation
import UIKit
// PresentAnimationController: Custom "present-like" animation
class PresentAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.5 // Duration of the animation
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromVC =…