问题
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
print("changed")
}
}
The iOS 13 application just goes to background without changing the mode (light/dark) but the "print" function is called. Is it possible to determine the moment when the mode really changed?
Thank You.
回答1:
I observed this myself as well.
The user interface toggles as soon as you go to the background, however - it immediately toggles back.
I guess you should simple follow the changes and react as needed.
You can find the current interface style by checking traitCollection.userInterfaceStyle
.
For instance:let isDark = traitCollection.userInterfaceStyle == .dark
来源:https://stackoverflow.com/questions/59139757/traitcollectiondidchange-strange-behavior