电流代码:
struct ContentView: View {
var body: some View {
ScrollView(.vertical/*, showsIndicators: false*/){
VStack(spacing: 0) {
ForEach ((0..<4).reversed(), id: \.self) {
Image("background\($0)").resizable()
.aspectRatio(contentMode: .fill)
.frame(width: UIScreen.main.bounds.width ,height:1000)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.red)
}
.edgesIgnoringSafeArea(.all)
}
}
我希望ScrollView出现底部至顶部,而不是上到底部。这有我的回答:
https://www.thirdrocktechkno.com/blog/implementing-reversed-scrolling-behaviour-behaviour-in-swiftui/
tldr:中的项目上
我的完整代码:
ScrollView(.vertical, showsIndicators: true, content: {
LazyVStack(alignment: .center, spacing: nil, pinnedViews: [], content: {
ForEach(1...5, id: \.self) { count in
ScrollView(.horizontal, showsIndicators: false, content: {
LazyHStack(alignment: .center, spacing: nil, pinnedViews: [], content: {
ForEach(1...10, id: \.self) { count in
Text("Placeholder \(count)").rotationEffect(Angle(degrees: 180)).scaleEffect(x: -1.0, y: 1.0, anchor: .center)
}
})
})
}
})
}).rotationEffect(Angle(degrees: 180)).scaleEffect(x: -1.0, y: 1.0, anchor: .center)
i我能够在uiscrollview中使用stackView来实现这一目标。 将您想要的任何内容放在StackView中,然后在viewController.viewdidloaddo
//flip the scrollview
scrollview.transform = CGAffineTransform(rotationAngle: Double.pi)
//flip the stackview
stackview.transform = CGAffineTransform(rotationAngle: Double.pi)
现在滚动浏览将从自下而上
ScrollView() {
// content
}
.defaultScrollAnchor(.bottom)