NOTE: This is not about the new default modal presentation style used in iOS 13.
I have a strange issue presenting a modal UINavigationController
.
Consider an UIViewController
that is inside an UINavigationController
:
When this code runs on iOS 13.0 :
@IBAction func btntap(_ sender: Any) {
let errorViewController = UIViewController()
errorViewController.view.backgroundColor = .blue
errorViewController.title = "Erro na solicitação"
let errorNavigation = UINavigationController()
errorNavigation.navigationBar.barTintColor = UIColor(red: 204/255, green: 0/255, blue: 0/255, alpha: 1.0)
errorNavigation.navigationBar.tintColor = UIColor.white
errorNavigation.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
errorNavigation.setViewControllers([errorViewController], animated: false)
errorNavigation.modalPresentationStyle = .automatic
self.present(errorNavigation, animated: true, completion: nil)
}
This happens:
Note the wrong height when we present the modal screen on the first time:
I want to continue using the card-like presentation, but I need to fix this wrong height issue on the first present.
This happens when the following requirements are met:
The presenting
UIViewController
is inside anUINavigationController
The presented
UIViewController
has special chars on its title ("ç", "ã", etc)The present is
animated true
Already tried some variations of layoutIfNeeded()
but none worked.
How can I present this with the right height on the first present?