如何在多语言ios应用程序中从左到右更改汉堡菜单?

时间:2017-04-28 07:37:43

标签: ios swift3 swrevealviewcontroller

目前我正在开发一个需要以阿拉伯语和英语显示的iOS应用程序。为此,我目前正在使用SWRevealviewcontroller。但是我要求如果用户从应用程序设置中选择阿拉伯语,则汉堡包菜单应该从左向右移动。 请告诉我们如何做到这一点。或者任何特定的教程都会对此有所帮助。

以下代码为:

    @IBOutlet weak var leftButton: UIBarButtonItem!

    @IBOutlet weak var rightButton: UIBarButtonItem!
    override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(self, selector: #selector(languageChanged(_:)), name: NSLocale.currentLocaleDidChangeNotification, object: nil)

        customSetup()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func languageChanged(_ note: Notification)
    {
        customSetup()
    }

    func customSetup()
    {
        let preferredLanguage = Locale.preferredLanguages[0] as NSString
        print(preferredLanguage)

        let storyboard = UIStoryboard(name: "Main", bundle: nil)

        if preferredLanguage.substring(with: NSMakeRange(0, 2)) == "ar" {
            leftButton.target = self.revealViewController()
            leftButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))

            rightButton.target = self.revealViewController()
            rightButton.action = #selector(SWRevealViewController.revealToggle(_:))

            revealViewController().rightViewController = storyboard.instantiateViewController(withIdentifier: "RearTableViewController") as? RevealTableTableViewController
            revealViewController().rearViewController = storyboard.instantiateViewController(withIdentifier: "RightViewController") as? RightViewController
        }
        else {
            revealViewController().rightViewController = storyboard.instantiateViewController(withIdentifier: "RightViewController") as? RightViewController
            revealViewController().rearViewController = storyboard.instantiateViewController(withIdentifier: "RearTableViewController") as? RevealTableTableViewController

            leftButton.target = self.revealViewController()
            leftButton.action = #selector(SWRevealViewController.revealToggle(_:))

            rightButton.target = self.revealViewController()
            rightButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))
        }
    }
}

但我在

收到以下错误
  if preferredLanguage.substring(with: NSMakeRange(0, 2)) == "ar" {
            leftButton.target = self.revealViewController()
            leftButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))

            rightButton.target = self.revealViewController()
            rightButton.action = #selector(SWRevealViewController.revealToggle(_:))

            revealViewController().rightViewController = storyboard.instantiateViewController(withIdentifier: "RearTableViewController") as? RevealTableTableViewController
            revealViewController().rearViewController = storyboard.instantiateViewController(withIdentifier: "RightViewController") as? RightViewController
        }

unwrapped value: Click here to see the image

1 个答案:

答案 0 :(得分:0)

您应该为它创建另一个故事板。