When I use storyboard segue, it is pretty smooth showing another viewcontroller onscreen. However, when I'm not using storyboard, just add a simple line of code with navigationController?.pushViewController(UIViewController(), animated: true)
, it's a little bit lagging in transition.
Also I read about Delay when pushing view controller (iOS). But even when I'm pushing an brand new viewcontroller (no extra code inside), the transition is still a little bit lagging, any idea?
Swift 5.3, Xcode 12
I was facing this same issue, tried adding to main thread, but apparently the problem was I was pushing the viewController created programatically, and it backgroundColor was nil. Just by setting the color in pushedViewController to something else, solved the issue.
self.view.backgroundColor = yourColor
In app delegate, set your window's background color to red.
window?.backgroundColor = .red
Also in the the pushed view controller, set its view to red.
view.backgroundColor = .red
I experienced the same issue when programmatically embedding my view controller in a UINavigationController.
I came across the same issue when I was drawing UI programmatically.
In my case, overriding loadView function solved my problem.
import UIKit
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "My tasks"
}
override func loadView() {
// You can load your view here. For simplicity, I just give it a background color
let v = UIView()
v.backgroundColor = UIColor.orange
view = v // This line does the magic
}
}
Viewcontroller is expecting to render view so add below view background color or set title
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Title"
self.view.backgroundColor = .red
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With