Search code examples
iosuiscrollviewuibuttonright-to-leftuistackview

UIStackView not reversed when viewDidLoad in RTL language


I have a UIStackView in Storyboard with structure as below and want to scroll it to a specific button in viewDidLoad.

enter image description here

This is how I'm scrolling it.

[self.scrollView scrollRectToVisible:button.frame animated:YES];

The problem is, when setting system language to a RTL language (such as Arabic), the direction of UIStackView and button.frame are still left to right in viewDidLoad, so the scroll position is incorrect.

What should I do to fix this?


Solution

  • As you have seen, frame setup is not completed in viewDidLoad.

    Move that code to viewDidAppear:

    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [self.scrollView scrollRectToVisible:button.frame animated:YES];
    }