iOS 9中RTL语言的行为

4
我们的应用程序支持RTL语言,如阿拉伯语和波斯语。
在iOS 9之后,导航控制器和选项卡控制器的行为已经改变。我只找到了这个链接ios-9-disable-support-for-right-to-left-language来解决这个问题。
我将这段代码写在我的appDelegate中,它可以很好地工作,并且导航栏和选项卡被设置为LTR。
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
    [[UINavigationBar appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
    [[UITabBar appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}

我的问题是:无法更改交互式弹出手势的方向。

输入图片描述


为什么你想要这样做? - Fogmeister
1
@Fogmeister,因为它的风格不好且不符合用户体验的规范。你可以更改语言并查看WhatsApp(他们已经解决了这个问题),但Telegram团队却没有解决这个问题。你有什么想法吗? - Mo Farhand
@Fogmeister 我同意你的看法,但在这种情况下我们需要这个功能,在苹果文档中也可以看到这一点: ~Flipping Cocoa Touch Views and Controls Programmatically` https://developer.apple.com/library/prerelease/ios/documentation/MacOSX/Conceptual/BPInternational/SupportingRight-To-LeftLanguages/SupportingRight-To-LeftLanguages.html - Mo Farhand
3
Mohamad,这个文档只描述了如何适应iOS 9中新的RTL UI控件,与你此处尝试做的相反。我强烈建议不要这样做;随着越来越多的应用程序开始链接到iOS 9,如果它们支持RTL语言,那么更多的应用程序将默认使用翻转过的UI。归根结底,你的应用程序将与系统的其余部分不一致。 - wakachamo
@wakachamo,感谢你的提示,兄弟。 - Mo Farhand
显示剩余3条评论
3个回答

3

我曾经遇到同样的问题,最终找到了解决方案。

你只需要为navigationController.view设置SemanticContentAttribute属性。

在rootViewController的viewDidLoad方法中实现:

[self.navigationController.view setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
[self.navigationController.navigationBar setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];

2

在Swift中

navigationController?.view.semanticContentAttribute = .forceRightToLeft
navigationController?.navigationBar.semanticContentAttribute =  .forceRightToLeft 

0
如果您正在创建自定义弹出窗口,有两种方法可以处理。
  1. 在.h文件中定义一个宏,在运行时检测是否为RTL语言。

    define IS_RTL [UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft

然后根据IS_RTL创建自定义布局。例如:

if (IS_RTL)
//Do Arabic Implementation
else
//Do other language implementation

如果您正在从Storyboard创建UI,则将约束设置为Lead或Trailing空间,第一个项目的值将是“Respect Language Direction”。

谢谢你的回答,但不幸的是,在iOS 9之后,我们无法在没有setSemanticContentAttribute的情况下完成它。无论如何,“Respect Language Direction”对于我们的对齐非常好,但对于我们的方向不起作用。 结论:像许多应用程序一样,我们尊重这种行为并上传到应用商店 :) - Mo Farhand

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接