删除 SwiftUI 子视图中的大量空白 [英] Removing large amounts of whitespace in a SwiftUI subview

查看:59
本文介绍了删除 SwiftUI 子视图中的大量空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

空白问题演示

当我在 NavigationView 中嵌套 NavigationView 时,大量空白将后退按钮和新的导航栏标题分开.我在设置 SwiftUI 视图方面做错了什么?

When I nest a NavigationView within a NavigationView, an enormous amount of whitespace separates the back button and the new navigation bar title. Is there something I'm doing wrong in terms of setting up my SwiftUI views?

import SwiftUI

struct Dashboard: View {
    @EnvironmentObject var user: User
    let courses = Course.exampleCourses()

    var body: some View {
        NavigationView {
            List(courses) { course in
                NavigationLink(destination: CourseView(course: course)) {
                    Text(course.name)
                }
            }.navigationBarTitle("Welcome, \(user.first)!")
        }
    }
}

import SwiftUI

struct CourseView: View {
    // @ObservedObject allows us to update views whenever values in course change
    @ObservedObject var course: Course
    @EnvironmentObject var user: User

    var body: some View {
        NavigationView {
            List {
                NavigationLink(destination: WritingPromptView(prompt: "What is your course goal, \(user.first)?", explanationText: "This is the answer", textLocation: self.$course.goal)) {
                    Text("Course Goal")
                }
                NavigationLink(destination: NotepadView(parent: self.course)) {
                    Text("Notepad")
                }
                NavigationLink(destination: WritingPromptView(prompt: "<Reflection prompt goes here>", explanationText: "<How to reflect goes here>", textLocation: self.$course.reflection)) {
                    Text("Reflection")
                }

            }.navigationBarTitle(course.name)
        }
    }
}

推荐答案

这是一个双导航栏.只需从您的 CourseView 中删除 NavigationView.如果您有 CourseView 的预览,您可能希望将其包装在 NavigationView 那里.

It's a double NavigationBar. Just remove NavigationView from your CourseView. If you have Previews for CourseView, you will probably want to wrap it NavigationView there.

这篇关于删除 SwiftUI 子视图中的大量空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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