Change interactivePopGestureRecognizer direction

痴心易碎 提交于 2019-12-11 07:29:33

问题


My app supports both English and Arabic. interactivePopGestureRecognizer works properly when using English, ie on swiping from left to right, it pops viewController. But when i am using arabic, I have changed the semanticContentAttribute from right to left.

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
    }

But the interactivePopGestureRecogniser is still from left to right. How can I change the direction of interactivePopGestureRecogniser such that it supports Arabic? I want to swipe from right to left to pop view controller on using Arabic language.


回答1:


After a lot of trials, the only solution worked for me was this:

Swift 3:

extension UIViewController {
    open override func awakeFromNib() {
        super.awakeFromNib()
        navigationController?.view.semanticContentAttribute = .forceRightToLeft
        navigationController?.navigationBar.semanticContentAttribute = .forceRightToLeft
    }
}

You can exclude the semantic attribute for certain types like:

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


来源:https://stackoverflow.com/questions/47525211/change-interactivepopgesturerecognizer-direction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!