SwiftUI反向滚动视图从下到上 [英] SwiftUI reverse ScrollView from bottom to top

查看:17
本文介绍了SwiftUI反向滚动视图从下到上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个ScrollView,使我可以从下向上滚动。 基本上我有一个渐变背景(底部黑色,顶部白色)。当我设置ScrollView时,我可以从白色向下滚动到黑色。我希望这个应用程序在ScrollView的底部启动,这样我就可以向上滚动了。(从黑到白)

谢谢!

当前编码:

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)

}   

}

推荐答案

我希望滚动视图从下到上显示,而不是从上到下显示。这就是我的答案:https://www.thirdrocktechkno.com/blog/implementing-reversed-scrolling-behaviour-in-swiftui/

TLDR:.rotationEffect(Angle(degrees: 180)).scaleEffect(x: -1.0, y: 1.0, anchor: .center)在滚动视图和滚动视图中的项目上

我的完整代码:


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)

这篇关于SwiftUI反向滚动视图从下到上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆