MoathOthman / MOLH

Localization helper for iOS apps mainly focusing on the LTR/RTL issue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Images is not mirrored in first view controller in navigation

bokhary3 opened this issue · comments

Hi @MoathOthman, firstly thanks for this great library,
There is a problem in the pod example, when change language to be arabic, image view in first ViewController not mirrored, if we set image view with tag = -1 in second view controller works fine, I see that if controller in navigation controller so it will loop on subviews in a navigation controller rather than a controller, I modified mirroringviewDidLoad method to handle.
This is my code:

@objc func mirroringviewDidLoad() {
        mirroringviewDidLoad()
        if UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft {
            if self is UINavigationController {
                if let viewController = (self as! UINavigationController).viewControllers.first {
                    loopThroughSubViewAndFlipTheImageIfItsNeeded(viewController.view.subviews)
                }
            } else {
                loopThroughSubViewAndFlipTheImageIfItsNeeded(self.view.subviews)
            }
        }
        // Do any additional setup after loading the view.
    }

@bokhary3 I advise to reference all the images that needs to be mirrored as an iboutlet collectoin ,
and flip them in one place .
you may add a collection in the superviewcontroller you may use and in view did load , loop through the images and flip them ,

so in the superviewcontroller or the viewcontroller

add @Iboutlet var imagesToFlip: [uiimageView]?
and in view did load

imagesToFlip.forEach{$0.image = $0.image?.flipifneeded()}
u need to import MOLH