traitCollectionDidChange strange behavior

冷暖自知 提交于 2021-02-19 01:49:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!