问题
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