覆盖 `preferredContentSizeCategory` 需要重启应用才能生效

问题描述

在我的 iOS 应用中,我在我的 preferredContentSizeCategory 子类上覆盖了 UIApplication 以返回自定义设置值:

class MyApplication: UIApplication {
    override var preferredContentSizeCategory: UIContentSizeCategory {
        // GeneralSettings.textSizeOverride is stored in UserDefaults
        GeneralSettings.textSizeOverride ?? super.preferredContentSizeCategory
    }
}

我希望可以在应用程序内配置文本大小,允许用户覆盖系统默认文本大小并为此应用程序设置特定值。所选值存储在 UserDefaults 中。

考虑到新的首选大小,我无法刷新应用的 UI,除非我强制关闭并重新启动应用。即使我重新实例化视图控制器堆栈,我也会看到基于 preferredContentSizeCategory 启动时的值的文本大小。

当用户更改应用的文本大小设置时,我会发布通知以尝试更新 UI:

NotificationCenter.default.post(
    name: UIContentSizeCategory.didChangeNotification,object: UIScreen.main,userInfo: [
        UIContentSizeCategory.newValueUserInfoKey: GeneralSettings.textSizeOverride!.rawValue
    ]
)

应用程序中的某些内容似乎在启动时缓存了 preferredContentSizeCategory 值,并且在下次启动之前不会使用 UIApplication 定义的值。有没有办法做到这一点?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...