我在内部切换应用程序语言(LTR-RTL),然后重新初始化故事板。
下面是这段代码:
let semanticContentAttribute: UISemanticContentAttribute = language == .Arabic ? .ForceRightToLeft : .ForceLeftToRight
UIView.appearance().semanticContentAttribute = semanticContentAttribute
UINavigationBar.appearance().semanticContentAttribute = semanticContentAttribute
问题是,所有呈现的视图控制器在关闭它时都会冻结3-6秒。
是什么导致了这种情况?
发布于 2017-01-28 02:34:09
不支持在appearance()
代理上设置semanticContentAttribute
。你会遇到许多其他的问题和错误,因为应用程序仍然认为它运行的语言不是你要覆盖的语言。
给你的应用程序添加一个语言切换器只会让它更令人困惑;用户希望他们的应用程序遵循他们的设备设置的语言。
发布于 2020-09-30 21:49:13
如果有人在找,我找了很长时间才找到解决方案。
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中):
https://stackoverflow.com/questions/41565402
复制相似问题