从右到左导航中的滑动方向错误

Kon*_*nko 3 objective-c right-to-left ios

当手机具有从右到左本地化功能时,我禁用视图旋转(选择希伯来语并且所有视图从左到右更改其位置时的处理):

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")){
    if (RightToLeft) {
        [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
        [[UINavigationBar appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
    }
}
Run Code Online (Sandbox Code Playgroud)

一切看起来都很好,但我需要从右向左滑动才能返回上一个视图控制器。如何设置从左到右的滑动方向以在 ViewController 之间导航?

Tom*_*Tom 6

我终于找到了一个为那些对班级进行子类化的人工作的人UINavigationController。你应该做这样的事情:

final class TestNavigationController: UINavigationController, UINavigationControllerDelegate {

    override func viewDidLoad() {
         super.viewDidLoad()
         self.delegate = self
    }

    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
         navigationController.view.semanticContentAttribute = UIView.isRightToLeft() ? .forceRightToLeft : .forceLeftToRight
         navigationController.navigationBar.semanticContentAttribute = UIView.isRightToLeft() ? .forceRightToLeft : .forceLeftToRight
    }
}

extension UIView {

    static func isRightToLeft() -> Bool {
        return UIView.appearance().semanticContentAttribute == .forceRightToLeft
    }
}
Run Code Online (Sandbox Code Playgroud)

您的 NavigationController 将动态地适应强制语义内容属性。我希望它有帮助。如果您有任何问题,请告诉我。