Ios 更改InteractiveEPoPGestureRecognitor方向

Ios 更改InteractiveEPoPGestureRecognitor方向,ios,objective-c,interactivepopgesture,Ios,Objective C,Interactivepopgesture,我的应用程序支持英语和阿拉伯语InteractivePopgestureRecognitor在使用英语时工作正常,即从左向右滑动时,它会弹出viewController。但是,当我使用阿拉伯语时,我将语义内容属性从右向左进行了更改 if([[[NSUserDefaults standardUserDefaults] objectForKey:@"LanguageCode"] isEqualToString:@"en"]) { [[UIView appearance] se

我的应用程序支持英语和阿拉伯语
InteractivePopgestureRecognitor
在使用英语时工作正常,即从左向右滑动时,它会弹出viewController。但是,当我使用阿拉伯语时,我将
语义内容属性
从右向左进行了更改

if([[[NSUserDefaults standardUserDefaults] objectForKey:@"LanguageCode"] isEqualToString:@"en"])
    {
        [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];       //View for English language
    }
    else
    {
        [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];       //mirror view for Arabic language
    }

但是,
InteractiveEPPGestureRecograiser
仍然是从左到右。如何更改InteractivePostureRecognitiser的方向,使其支持阿拉伯语?我想用阿拉伯语从右向左滑动弹出视图控制器

经过多次试验后,唯一对我有效的解决方案是:

Swift 3

extension UIViewController {
    open override func awakeFromNib() {
        super.awakeFromNib()
        navigationController?.view.semanticContentAttribute = .forceRightToLeft
        navigationController?.navigationBar.semanticContentAttribute = .forceRightToLeft
    }
}
可以排除某些类型的语义属性,例如:

UIView.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).semanticContentAttribute = .forceLeftToRight

如果有人在寻找,我在寻找了很长时间后找到了解决办法

前面的回答可能会导致UI挂起/冻结

UI冻结/挂起的原因是,在根视图上执行手势时,UINavigationController缺少对根视图控制器的检查。有几种方法可以解决这个问题,下面是我所做的

您应该将UINavigationController子类化,这是正确的方法,可以按如下方式添加工具:

class RTLNavController: UINavigationController, UINavigationControllerDelegate, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //  Adding swipe to pop viewController
        self.interactivePopGestureRecognizer?.isEnabled = true
        self.interactivePopGestureRecognizer?.delegate = self

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

    //  Checking if the viewController is last, if not disable the gesture
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if self.viewControllers.count > 1 {
            return true
        }
        
        return false
    }
}

extension UIView {
    static func isRightToLeft() -> Bool {
        return UIView.appearance().semanticContentAttribute == .forceRightToLeft
    }
}
资源:

原始问题:

答案用于解决方案:

其他可能效果更好的解决方案(但在Objective-C中):


从内存中删除应用程序并重新启动,这次滑动方向应该正常。您找到了有效的解决方案吗?