[英]I want to change the direction of the ScrollView, but it reverses everything
我試圖讓 ScrollView 從右到左開始顯示
我找到了這個解決方案,但它以錯誤的方式扭轉了一切
.flipsForRightToLeftLayoutDirection(true)
.environment(\.layoutDirection, .rightToLeft)
將此添加到 ScrollView
我只是想反轉ScrollView的開始,不是一切
struct AdsView: View {
var body: some View {
VStack(spacing: 1){
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 20) {
ForEach(0..<5) { item in
VStack(alignment: .trailing) {
Image("test")
.resizable()
.scaledToFit()
.cornerRadius(20)
.shadow(color: .black.opacity(0.1), radius: 20, x: 20, y: 20)
.frame(maxWidth: 150, maxHeight: 200)
Text("start here")
Text("new").foregroundColor(Color.red)
}
}
}.padding()
}
.flipsForRightToLeftLayoutDirection(true)
.environment(\.layoutDirection, .rightToLeft)
}
}
}
一種解決方案是對ScrollView
和內容使用相反的比例。
使用 Xcode 13.3 / iOS 15.4 測試
這是主要部分:
.scaleEffect(CGSize(width: -1, height: 1))
}
.scaleEffect(CGSize(width: -1, height: 1))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.