Text 试图设置一个包含多行文本的可滚动视图,但当应用程序运行时,滚动时运行速度非常慢

Text 试图设置一个包含多行文本的可滚动视图,但当应用程序运行时,滚动时运行速度非常慢,text,swiftui,scrollview,ios14,lazyvstack,Text,Swiftui,Scrollview,Ios14,Lazyvstack,我正在尝试设置一个Instructions视图,该视图将通过文本显示运行我的应用程序的说明(适用于那些不太了解其工作原理并需要逐步说明的人) 我写了下面的代码,但是当我运行它的时候,当我打开这个特定的视图时,它运行得非常慢,滚动非常慢,直到它什么都没做,就像没有崩溃的崩溃一样 我的代码: NavigationView { ScrollView { LazyVStack(alignment: .leading) { paddi

我正在尝试设置一个Instructions视图,该视图将通过文本显示运行我的应用程序的说明(适用于那些不太了解其工作原理并需要逐步说明的人)

我写了下面的代码,但是当我运行它的时候,当我打开这个特定的视图时,它运行得非常慢,滚动非常慢,直到它什么都没做,就像没有崩溃的崩溃一样

我的代码:

NavigationView {
        ScrollView {
            LazyVStack(alignment: .leading) {
                padding()
                Text("Main Screen")
                    .font(.title2)
                    .foregroundColor(.purple)
                Text("This is the description text for the Main Screen")
                    .padding(.all)
                    .font(.title3)
                    .foregroundColor(.pink)
            }.padding(.leading)

            LazyVStack(alignment: .leading) {
                Text("Log In")
                    .font(.title2)
                    .foregroundColor(.purple)
                Text("This is the description text for the Login")
                    .padding(.all)
                    .font(.title3)
                    .foregroundColor(.pink)
                padding()
            }.padding(.leading)

            LazyVStack(alignment: .leading) {
                Text("Workout")
                    .font(.title2)
                    .foregroundColor(.purple)
                Text("This is the description text for Workouts.")
                    .padding(.all)
                    .font(.title3)
                    .foregroundColor(.pink)
                padding()
            }.padding(.leading)

            LazyVStack(alignment: .leading) {
                Text("Logout")
                    .font(.title2)
                    .foregroundColor(.purple)
                Text("This is the description text for Logout")
                    .padding(.all)
                    .font(.title3)
                    .foregroundColor(.pink)
                padding()
            }
            .padding(.leading)

            LazyVStack(alignment: .leading) {
                Text("Settings")
                    .font(.title2)
                    .foregroundColor(.purple)
                Text("This is the description text for Settings")
                    .padding(.all)
                    .font(.title3)
                    .foregroundColor(.pink)
                padding()
            }
            .padding(.leading)


        }
        .navigationTitle("Instructions")
    }
我的代码,在“描述文本”中的代码比上面的要多,每个新的类别或标题都由一个新的LazyVStack块和一组2个文本组成,如上所述。整个视图应由8-10个LazyVStack块组成

下面是我正在尝试做的事情的示意图:

基本上,我只是想创建一个可滚动的视图,其中只包含一个标题和标题描述的文本。将有多达10个标题和描述-所有文本


知道我做错了什么吗?我想问题出在你的
padding()
s上。尝试移除它们

您应该向视图中添加填充,如下所示:

Text("content")
.padding()
LazyVStack(alignment: .leading, spacing: 32) { // <- spacing
                    Text("Main Screen")
                        .font(.title2)
                        .foregroundColor(.purple)
                    Text("This is the description text for the Main Screen")
                        .padding(.all)
                        .font(.title3)
                        .foregroundColor(.pink)
                }.padding(.leading)
正如您在中所看到的,
填充(41;
是一个视图修饰符,应该在
视图上调用

要在组件之间添加额外空间,可以执行以下操作之一:

1-通过如下方式传递
间距设置
LazyVStack
组件之间的间距:

Text("content")
.padding()
LazyVStack(alignment: .leading, spacing: 32) { // <- spacing
                    Text("Main Screen")
                        .font(.title2)
                        .foregroundColor(.purple)
                    Text("This is the description text for the Main Screen")
                        .padding(.all)
                        .font(.title3)
                        .foregroundColor(.pink)
                }.padding(.leading)

我去掉了填充物(),它确实看起来效果更好。我发现主标题“说明”在视图中比我想要的要低得多。这个信息帮助很大。它们都可以放在一个LazyVStack()中吗?当然,这样会更好,但您应该将它们放在多个
组中。在另一个视图中,视图不能超过个。因此,在LazyVStack中,每个标题文本和描述文本的组内-可以完成吗?是的,当然可以。这是可以做到的。