首页 > 解决方案 > UINavigationController 改变 InteractivePopGesture 方向

问题描述

我正在设计一个从右到左的应用程序。我通过使用这行代码完成了所有的 rtl:

UIView.appearance().semanticContentAttribute = .forceRightToLeft

这适用于所有期望我的导航控制器的交互式弹出手势的东西。segue的方向是正确的:

在此处输入图像描述

但是当我想使用弹出手势(从左边缘滑动到右边缘)时,视图从另一侧变得可见。
我应该如何改变它?
我尝试将边缘更改为 .right ,但这禁用了手势识别器:

let gesture = interactivePopGestureRecognizer as! UIScreenEdgePanGestureRecognizer
    gesture.edges = .right

标签: iosswiftswift3uinavigationcontrolleruigesturerecognizer

解决方案


您应该使用此扩展名更改 bothviewnavigationBar语义属性:

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

推荐阅读