uiscrollview - SwiftUI ScrollView horizontal RTL not working correctly
问题描述
I'm trying to support RTL mode on my ios , which was built using swiftUI every is fine while doing this to change the layour direction :
.environment(\.layoutDirection, .rightToLeft)
Only with horizontal ScrollView , it's not work correctly
when i do this :
ScrollView(.horizontal) {
HStack{
Text("b1")
Text("b2")
Text("b3")
}
} .environment(\.layoutDirection, .rightToLeft)
Items positions will rotate , but the HSTACK will stay always on the left like the screenshot below :
Any solution or hack to make it to the right ?
解决方案
我找到了一个 hack 来使用.flipsForRightToLeftLayoutDirection(true)
和.rotation3DEffect
就像滚动视图将被翻转一样,您需要将 HStack 的每个项目翻转到.rotation3DEffect
ScrollView(.horizontal) {
HStack{
Text("b1")
.rotation3DEffect(Angle(degrees: 180), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
Text("b2")
.rotation3DEffect(Angle(degrees: 180), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
Text("b3")
.rotation3DEffect(Angle(degrees: 180), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
}
}.flipsForRightToLeftLayoutDirection(true)
.environment(\.layoutDirection, .rightToLeft)
推荐阅读
- mysql - 更改 spring jpa 现有表列类型
- c++ - 如何从平面缓冲区中反序列化联合结构的 void* 值的大小
- python-3.x - 我应该如何从 Python 中的字符串自动创建变量?
- r - 我想创建一个按订单 ID 分组的最大日期列
- sql - 访问查询:无法获得正确的计数
- kernel - 如何使用 seccomp_release libseccomp?
- swift - “协议”类型的值没有成员“功能”
- node.js - 将图像上传到您的网站 Node js 的正确方法是什么
- android - 如何检测该应用程序是否在测试版 Android 上运行?
- javascript - 如何修复“vue.min.js:6 TypeError: keyframes.insertRule 不是函数”?