如何以编程方式将 iOS 应用程序的布局从 LTR 更改为 RTL,反之亦然?

How to change the layout of an iOS app programmatically from LTR to RTL and vice versa?

因此,我尝试以编程方式将应用语言从 English 更改为 RTL 语言。文本已本地化,但布局仍然是 LTR,直到我重新启动 RTL 生效的应用程序。

有没有办法在不重启应用的情况下实现这一点?

我最终使用 setSemanticContentAttribute 方法在运行时强制 RTL,如下所示:

if ([NSLocale characterDirectionForLanguage:languageCode] == NSLocaleLanguageDirectionRightToLeft) {
    if ([[[UIView alloc] init] respondsToSelector:@selector(setSemanticContentAttribute:)]) {
        [[UIView appearance] setSemanticContentAttribute:
         UISemanticContentAttributeForceRightToLeft];
    }
}
else {
    if ([[[UIView alloc] init] respondsToSelector:@selector(setSemanticContentAttribute:)]) {
        [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
    }
}