
Transitioning between view controllers means moving from one screen to another in an app. When animations are added, the transition becomes visually smooth and engaging (e.g., slide,...
Transitioning between view controllers means moving from one screen to another in an app. When animations are added, the transition becomes visually smooth and engaging (e.g., slide, fade, flip).
Switching from one View Controller to another
Can be:
Common animation styles:
navigationController?.pushViewController(secondVC, animated: true)
present(secondVC, animated: true, completion: nil)
dismiss(animated: true, completion: nil)
You can customize modal transitions:
secondVC.modalTransitionStyle = .flipHorizontal
present(secondVC, animated: true)
| Style | Description |
|---|---|
.coverVertical |
Slide up (default) |
.flipHorizontal |
Flip animation |
.crossDissolve |
Fade effect |
.partialCurl |
Page curl |
You can create your own animation:
UIView.transition(with: self.view, duration: 0.5, options: .transitionFlipFromRight, animations: {
self.present(secondVC, animated: false)
})
Draw:
Screen 1 โโ(Animated Transition)โโโถ Screen 2
(Slide / Fade / Flip)
Screen 1:
Code:
@IBAction func goNext(_ sender: UIButton) {
let vc = storyboard?.instantiateViewController(withIdentifier: "SecondVC") as! SecondViewController
vc.modalTransitionStyle = .crossDissolve
present(vc, animated: true)
}
๐ Result:
Transition = moving between screens
Types:
Animations:
Use:
present()pushViewController()Customize with:
modalTransitionStyleKeep animations smooth and consistent
Open this section to view and download past papers
Click on Show Past Papers to load available exam papers.