I override traitCollectionDidChange
on a view controller and have noticed that it's been called twice on suspending the application.
In addition, a check if the trait collection has a different color appearance returns:
- the first time execution - the opposite
userInterfaceStyle
- the second time execution - the original
userInterfaceStyle
.
class ViewController: UIViewController {
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
print(traitCollection.userInterfaceStyle.rawValue);
}
}
}