RTL语言的iOS后退手势
我已通过编程方式为iOS应用程序启用了后退手势。对于默认区域和语言,它运行良好。应用程序具有用户可以更改语言的功能,即自定义本地化。但对于像阿拉伯语这样的RTL语言,应用程序内容是从右到左的RTL语言的iOS后退手势,ios,swipe-gesture,Ios,Swipe Gesture,我已通过编程方式为iOS应用程序启用了后退手势。对于默认区域和语言,它运行良好。应用程序具有用户可以更改语言的功能,即自定义本地化。但对于像阿拉伯语这样的RTL语言,应用程序内容是从右到左的 [[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft]; 但从左边刷回去是有效的。若我将设备语言设置为阿拉伯语,那个么它可以从右侧工作 我想通过编程实现这一点,请让我知道
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
但从左边刷回去是有效的。若我将设备语言设置为阿拉伯语,那个么它可以从右侧工作
我想通过编程实现这一点,请让我知道,我如何从应用程序中为RTL语言的背面手势设置滑动方向,无论设备的语言是什么。通过使用
UISemanticContentAttribute
它只会影响任何
尤维尤
要完成滑动方向,您需要使用
UIUserInterfaceLayoutDirection
也适用于手势和完整的
RTL/LTR支持
首先,从AppDelegate注释以下行:
/@UIApplicationMain
之后,您需要创建一个名为applicationsubclassing的类
ui应用程序
和覆盖userInterfaceLayoutDirection
以能够
根据应用程序中使用的语言(如果其LTR或RTL)进行切换:
import UIKit
class Application: UIApplication,UIApplicationDelegate {
override open var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection {
get {
if language == .RTL {
return .rightToLeft
}else {
return .leftToRight
}
}
}
}
最后创建名为main.swift
的swift文件,并添加以下内容
其中一行:
import Foundation
import UIKit
CommandLine.unsafeArgv.withMemoryRebound(to:
UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)) {argv in
_ = UIApplicationMain(CommandLine.argc, argv,
NSStringFromClass(Application.self), NSStringFromClass(AppDelegate.self))
}
<代码>导入基础
导入UIKit
使用MemoryRebound(到:
UnsafeMutablePointer.self,容量:Int(CommandLine.argc)){argv-in
_uu=UIApplicationMain(CommandLine.argc、argv、,
NSStringFromClass(Application.self)、NSStringFromClass(AppDelegate.self))
}
现在将在每个屏幕上调用userInterfaceLayoutDirection
多次,但您必须控制是否需要RTL或LTR。通过使用
UISemanticContentAttribute
它只会影响任何需要的内容
尤维尤
要完成滑动方向,您需要使用
UIUserInterfaceLayoutDirection
也适用于手势和完整的
RTL/LTR支持
首先,从AppDelegate注释以下行:
/@UIApplicationMain
之后,您需要创建一个名为applicationsubclassing的类
ui应用程序
和覆盖userInterfaceLayoutDirection
以能够
根据应用程序中使用的语言(如果其LTR或RTL)进行切换:
import UIKit
class Application: UIApplication,UIApplicationDelegate {
override open var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection {
get {
if language == .RTL {
return .rightToLeft
}else {
return .leftToRight
}
}
}
}
最后创建名为main.swift
的swift文件,并添加以下内容
其中一行:
import Foundation
import UIKit
CommandLine.unsafeArgv.withMemoryRebound(to:
UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)) {argv in
_ = UIApplicationMain(CommandLine.argc, argv,
NSStringFromClass(Application.self), NSStringFromClass(AppDelegate.self))
}
<代码>导入基础
导入UIKit
使用MemoryRebound(到:
UnsafeMutablePointer.self,容量:Int(CommandLine.argc)){argv-in
_uu=UIApplicationMain(CommandLine.argc、argv、,
NSStringFromClass(Application.self)、NSStringFromClass(AppDelegate.self))
}
现在将在每个屏幕上调用userInterfaceLayoutDirection
多次,但您必须控制是否需要RTL或LTR。它不起作用!和显示错误消息('UIApplicationMain'属性不能在包含顶级代码的模块中使用)实际滑动此getter解决了我的反向滑动问题,但它破坏了应用程序中的其他布局。你有没有建议我还可以使用哪些方法,或者有一些UserDefaults键需要覆盖?我还设置了自定义UIView.appearance().semanticContentAttribute和AppleLanguages、AppleTextDirection、,NSForceRightToLeftWritingDirection@TarasNikulin,您需要重新布局的东西,如果它打破了,例如从nib唤醒标签或viewdidload。它不工作!和显示错误消息('UIApplicationMain'属性不能在包含顶级代码的模块中使用)实际滑动此getter解决了我的反向滑动问题,但它破坏了应用程序中的其他布局。你有没有建议我还可以使用哪些方法,或者有一些UserDefaults键需要覆盖?我还设置了自定义UIView.appearance().semanticContentAttribute和AppleLanguages、AppleTextDirection、,NSForceRightToLeftWritingDirection@TarasNikulin,您将需要重新布局的东西,如果它打破,如标签在唤醒从nib或viewdidload。