I'm redoing some things in a legacy app. One of the key things - before it used self-made push view controller animations, so view controllers that were "pushed" (not in a UINavigation sense, just an animation that looks like that) into view will load\appear offscreen and be moved into screen.
The new demand is to use UINavigationController. The app works, but the view controllers that are pushed into the main controller for the first time visibly take a few seconds to load and show their contents, while before that time was swallowed by the animation.
Is there a way to load controllers into memory (and call viewDidLoad) before pushing them, and call viewDidAppear in the beginning of the animation? The set of controllers used is fixed, so they can maybe be loaded all on appearance of UINavigationControler?
(Everything is done programmatically, no storyboards)
Class those controllers are based on:
class CPProgress: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = ColorTheme.bgFFF000
setupView ()
}
let progress: UIProgressView = {
let ctrl = UIProgressView ()
// some looks stuff here
return ctrl
} ()
let btnContinue: UIButton = {
let ctrl = UIButton ()
ctrl.backgroundColor = ColorTheme.text04F
ctrl.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .medium)
ctrl.setTitleColor(UIColor.white, for: .normal)
ctrl.setTitle(NSLocalizedString("survey_next_step_button_caption", comment: ""), for: .normal)
ctrl.layer.cornerRadius = 10
ctrl.translatesAutoresizingMaskIntoConstraints = false
return ctrl
} ()
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
rotate (isPortrait: Orientation.isPortrait(size: size)) // func for changing which constraints are active depending on the device orientation
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
rotate (isPortrait: UIViewController.layoutShouldBePortrait()) // func for changing which constraints are active depending on the device orientation
self.navigationItem.title = Constants.sampleTitle
}
func setupView () {
self.navigationItem.hidesBackButton = true
let item = UIBarButtonItem(customView: self.close)
self.navigationItem.setLeftBarButton(item, animated: false)
self.navigationItem.title = NSLocalizedString("scale_title", comment: "")
}
}
setupView() is overridden in all derived classes and contains things like layout constants. viewDidAppear() is also overridden and contains calculations on some data (that can be different each time it's shown) and setting images for a control and has UIImageView in a UIScrollView and has to center it when on screen.