2

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 : enter image description here

Any solution or hack to make it to the right ?

4

2 回答 2

3

我找到了一个 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)
于 2020-04-14T01:39:58.560 回答
0

作为一个黑客,你可以从这个开始:

var body: some View {
    GeometryReader { geom in
        ScrollView(.horizontal) {
            HStack {
                Text("b1")
                Text("b2")
                Text("b3")
            }.environment(\.layoutDirection, .rightToLeft)
             .padding(.leading, geom.size.width - 100) // adjust for the number of items
        }
    }
}
于 2020-04-12T05:42:33.413 回答