In my iOS app, I have overridden preferredContentSizeCategory
on my UIApplication
subclass to return a custom setting value:
class MyApplication: UIApplication {
override var preferredContentSizeCategory: UIContentSizeCategory {
// GeneralSettings.textSizeOverride is stored in UserDefaults
GeneralSettings.textSizeOverride ?? super.preferredContentSizeCategory
}
}
I want the text size to be configurable from within the app, allowing a user to override the system default text size and set a value specific for this app. The selected value in stored in UserDefaults
.
I can't get the app's UI to refresh taking account of the new preferred size, unless I force quite and relaunch the app. Even if I re-instantiate the stack of view controllers, I see the text sizes based on the value that preferredContentSizeCategory
had upon launch.
When the user changes the app's text size setting, I am posting a notification to try to get the UI to update:
NotificationCenter.default.post(
name: UIContentSizeCategory.didChangeNotification,
object: UIScreen.main,
userInfo: [
UIContentSizeCategory.newValueUserInfoKey: GeneralSettings.textSizeOverride!.rawValue
]
)
It seems like something in the application has cached the preferredContentSizeCategory
value at launch, and won't use the UIApplication
-defined value until next launch. Is there a way to achieve this?
question from:
https://stackoverflow.com/questions/65881545/overriding-preferredcontentsizecategory-requires-an-app-restart-to-take-effect 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…