RTL language behavior in iOS 9

落花浮王杯 提交于 2019-12-23 18:04:22

问题


Our app supports RTL language like Arabic, Persian.

After iOS 9 the navigation controller and tab bar controller behavior has been changed. I found only this link ios-9-disable-support-for-right-to-left-language for solve this problem

I write this code in my appDelegate and it works fine and navigation bar and tab bar set as LTR.

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
    [[UINavigationBar appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
    [[UITabBar appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}

But my problem is: I can't change interactive pop gesture Direction .


回答1:


I was struggling with same problem and finally found solution

you just need to set SemanticContentAttribute for navigationController.view

in the rootViewController's viewDidLoad:

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



回答2:


In Swift

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



回答3:


If your are creating custom pop up, two way you can handle this.

  1. Define a macro in .h file to detect whether it is RTL language or not in runtime.

    define IS_RTL [UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft

then create custom layout according if IS_RTL.Like

if (IS_RTL)
//Do Arabic Implementation
else
//Do other language implementation
  1. If you are creating UI from Storyboard, the set constraint to Lead or Trailing space and value of First Item will be Respect Language Direction


来源:https://stackoverflow.com/questions/32932463/rtl-language-behavior-in-ios-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!