小编Adh*_*ouf的帖子

“traitCollectionDidChange”在 iOS 17.0 中已弃用。我如何使用替换品?

我正在尝试使用此功能,但它不适用于 iOS 17。\n我想每次在深色和浅色模式之间切换时进行更改。

\n

这是我的功能:

\n
override 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}\n
Run Code Online (Sandbox Code Playgroud)\n

这就是问题所在:

\n
\n

\xe2\x80\x98traitCollectionDidChange\xe2\x80\x99 在 iOS 17.0 …

user-interface uikit ios swift uitraitcollection

1
推荐指数
1
解决办法
1589
查看次数

标签 统计

ios ×1

swift ×1

uikit ×1

uitraitcollection ×1

user-interface ×1