我想制作一个卷轴,这将使我有可能从下到顶部滚动。 基本上,我有梯度背景(底部 - 黑色,顶部 - 白色)。当我设置卷轴时,我可以scr ...

问题描述 投票:0回答:2

电流代码:

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:
xcode uiscrollview swiftui scrollview xcode11
2个回答
20
投票
在scrollview和scrollview

中的项目上 我的完整代码: 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)

现在滚动浏览将从自下而上
    

1
投票

ScrollView() { // content } .defaultScrollAnchor(.bottom)

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.