I'm trying to determine when the value of a view controller's navigationTitleAlignment trait changes. According to the documentation for UITraitCollection.navigationTitleAlignment, it states:
When the system has resolved an alignment for the title, this reports that concrete alignment, Leading or Center, even when the client has not set a preference. Otherwise it reports Automatic.
I created a simple test app with a nav controller as the root which in turn creates a simple view controller as its root.
In ViewController.swift I added the following:
override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)
if #available(iOS 27.2, *) {
registerForTraitChanges([UITraitNavigationTitleAlignment.self]) { (traitEnvironment: Self, previousTraitCollection: UITraitCollection) in
// The following is never called
print("self.traitCollection.navigationTitleAlignment = \(traitEnvironment.traitCollection.navigationTitleAlignment)")
}
}
}
When I run the app on a fully open simulated iPhone Duo running iOS 27.2 (or iOS 27.3 beta 2) and rotate between landscape and portrait, the title moves between left (landscape) and center (portrait) but the trait change is never called. The actual value for self.traitCollection.navigationTitleAlignment is always .automatic.
So when is the alignment actually ever resolved by the system? Why does it never change from "automatic"?
Is this a bug in UKit or a misunderstanding on my part? Or is this a bug in the simulator? I don't have a real iPhone Duo to test on. No other device (iPhone or iPad) ever switches the title alignment. It's only the iPhone Duo. It seems to always be left-aligned except when the Duo is open and in portrait, then it's centered.
This trait is intended to be used within a custom title view itself. The trait is not available set on the navigation controller or the top view controller. The intention is for the trait to be read by the custom title view to ensure any internal horizontal alignment it applies matches the system's alignment. We will update our documentation to clarify this.
If you require the title alignment in your view controller itself, please do file a feedback report requesting this change with a test project demonstrating the use case.
Thank you!