How to force quot;Respect Language Directionquot; from RTL to LTR and vice versa(如何强制“尊重语言方向从 RTL 到 LTR,反之亦然)
问题描述
我有一个使用自动布局的应用程序.
I have an application which uses Auto Layouts.
当用户选择他或她的设备电话语言时,该应用会完美地切换 RTL 和 LTR 语言.所有文本均已本地化,并且语言方向有效.
The app switches RTL and LTR languages perfectly when the user selects he's or her's device phone language. All texts are localized, and language directions are working.
我在应用程序内还有一个按钮,可以在不重新启动应用程序的情况下更改其语言.这也很有效,所有文本都被替换了.
I also have a button inside the app, to change it's language without restarting the app. This also works great, and all texts are being replaced.
问题在于,当用户从应用程序中更改语言时,具有讽刺意味的是,我预先定义的约束中的尊重语言方向"选项没有得到尊重.
The problem is that when the user changes the language from within the app, "Respect Language Direction" option in the constraints i have pre-defined is ironically not respected.
有什么想法吗?
推荐答案
最终,我设法解决了这个问题.
Eventually, I have managed to solve this issue.
我找不到强制更改 RTL - LTR 自动布局约束的方法,因此我决定为每个语言方向复制 2 个额外的故事板.所以,实际上我的应用现在包含 3 个故事板 - Main.storyboard、StoryboardRTL.storyboard 和 StoryboardLTR.storyboard.
I couldn't find a way to force the change the RTL - LTR auto layout constraints, so i have decided to duplicate 2 additional storyboards for each language direction. So, actually my app now contains 3 storyboards - Main.storyboard, StoryboardRTL.storyboard and StoryboardLTR.storyboard.
主要处理从iDevice上的设置执行时语言方向的变化,并且RTL/LTR有自己的方向,以支持从应用程序内部更改应用程序语言.
Main handles changes in language direction when it is performed from the settings on the iDevice, and RTL / LTR is has it's own orientation, to support changing the app language from inside the app.
当用户选择更改为 RTL 语言时,我在 UserDefaults 中设置所选语言:
When the user selects to change to an RTL language, I set the selected language in the UserDefaults:
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"he", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
在我调用我在 AppDelegate 中编写的方法之后,它会根据语言布局更改情节提要.
and right after i call a method i have written in the AppDelegate, which changes the storyboard according to the language layout.
- (void)reloadStoryboard
{
UIStoryboard *storyboard;
switch ([AALanguageManager getCurrentLanguage]) {
case CurrentLanguageRTL:
storyboard = [UIStoryboard storyboardWithName:@"StoryboardRTL" bundle:[NSBundle mainBundle]];
break;
default:
storyboard = [UIStoryboard storyboardWithName:@"StoryboardLTR" bundle:[NSBundle mainBundle]];
break;
}
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
}
这对用户来说就像应用重新启动一样,并显示具有 RTL/LTR 布局的正确情节提要.当用户再次重新启动应用程序时,选择的语言已经设置好,主情节提要显示出来,所有的布局都根据选择的语言正确.
This looks to the user as if the app restarted, and display the proper storyboard with the RTL / LTR layout. When the user restarts the app again, the selected language is already set, and the main storyboard is displayed, with all the correct layout according to selected language.
这篇关于如何强制“尊重语言方向"从 RTL 到 LTR,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何强制“尊重语言方向"从 RTL 到 LTR,反之亦然
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01