3

To change LTR to RTL I am using one storyboard with autolayout constraints leading and trailing. On the button click of change language to Arabic/English. I am calling switchLanguage(). Which changes the LTR to RTL and vice versa. All layout seems to be good.

The issue is after changing semanticContentAttribute from .forceLeftToRight to .forceRightToLeft or vice versa multiple times. The app navigations seems to be very slow and I have noticed the CPU usage reaches to 99%. The more you switch language the more is slower.

func swichLanguage {
    if Lang.current = .ar {
        UIView.appearance().semanticContentAttribute = .forceRightToLeft
    } else {
        UIView.appearance().semanticContentAttribute = .forceLeftToRight
    }

    let sb = UIStoryboard.init(name: "Main", bundle: nil)
    let vc = sb.instantiateInitialViewController()
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.window?.rootViewController = vc
}
Vignesh S
  • 39
  • 4
  • hmmm, I really don't know. previously I was using the approach before iOS 9.0 that I demonstrated in http://stackoverflow.com/questions/31877140/how-can-i-set-localised-direction-within-applicationrtl-if-user-select-arabic. Changing the semanticContentAttribute property was only a small test I did to update my answer. I don't have a real app therefore I didnt face your problem. – hasan Feb 26 '17 at 13:53
  • Are you testing on real device? what is that real device? – hasan Feb 26 '17 at 13:57
  • I am just trying to throw some ideas here. so, I am usually dismiss all controller and reaches my first view controller when I change language. Do you do that or you just force the layout? try to dismiss all controllers and go to root controllers maybe that solves the slow problem. – hasan Feb 26 '17 at 14:03
  • Thank you. Since the change language button is in rootviewcontroller. I am not able to dismiss it. Temporaly I have fixed by changing semanticContentAttribute for all Subviews in viewDidLoad() – Vignesh S Feb 28 '17 at 05:07
  • You may check out my solution, it works well: http://stackoverflow.com/questions/27685775/ios-7-force-view-layout-flip-to-rtl-without-language-change/42430254#42430254 – Sayakiss Mar 02 '17 at 10:36
  • Solution works good but still facing performance issue. – Vignesh S Mar 06 '17 at 06:27
  • @VigneshS I have same issue, app is being slow, did you find solution? – Safwan Hijazi Aug 25 '17 at 17:14
  • Setting semanticContentAttribute on the appearance() proxy is not supported. You're going to run into many other issues and bugs since the app still believes it's running in a language that isn't the one you're overriding. Adding a language switcher to your app is only going to make it more confusing; users expect their apps to follow the language that their device is set to. – wakachamo Sep 22 '17 at 06:17
  • @VigneshS I have same issue, app navigations is very slow, did you find solution? – OuSS Oct 23 '19 at 08:27

0 Answers0