首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >挂起(冻结)问题UISemanticContentAttribute = .ForceRightToLeft

挂起(冻结)问题UISemanticContentAttribute = .ForceRightToLeft
EN

Stack Overflow用户
提问于 2017-01-10 17:29:43
回答 2查看 403关注 0票数 0

我在内部切换应用程序语言(LTR-RTL),然后重新初始化故事板。

下面是这段代码:

代码语言:javascript
运行
复制
let semanticContentAttribute: UISemanticContentAttribute = language == .Arabic ? .ForceRightToLeft : .ForceLeftToRight

UIView.appearance().semanticContentAttribute = semanticContentAttribute
UINavigationBar.appearance().semanticContentAttribute = semanticContentAttribute

问题是,所有呈现的视图控制器在关闭它时都会冻结3-6秒。

是什么导致了这种情况?

EN

回答 2

Stack Overflow用户

发布于 2017-01-28 02:34:09

不支持在appearance()代理上设置semanticContentAttribute。你会遇到许多其他的问题和错误,因为应用程序仍然认为它运行的语言不是你要覆盖的语言。

给你的应用程序添加一个语言切换器只会让它更令人困惑;用户希望他们的应用程序遵循他们的设备设置的语言。

票数 0
EN

Stack Overflow用户

发布于 2020-09-30 21:49:13

如果有人在找,我找了很长时间才找到解决方案。

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

你应该子类化UINavigationController,这是正确的方法,如下所示添加实现:

代码语言:javascript
运行
复制
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中):

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41565402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档