我正在尝试使用此功能,但它不适用于 iOS 17。\n我想每次在深色和浅色模式之间切换时进行更改。
\n这是我的功能:
\noverride func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {\n super.traitCollectionDidChange(previousTraitCollection)\n\n // Check if the user interface style has changed\n if self.traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {\n // User interface style has changed (light to dark or vice versa)\n if self.traitCollection.userInterfaceStyle == .light {\n // Code to execute in light mode\n print("App switched to light mode")\n } else {\n // Code to execute in dark mode\n print("App switched to dark mode")\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n这就是问题所在:
\n\n\xe2\x80\x98traitCollectionDidChange\xe2\x80\x99 在 iOS 17.0 …