SwiftUI - 为什么导航栏和我编写的第一个组件之间有空格?
我有一个 SwiftUI 视图,其顶部如下所示:
其中“命名您的项目”是一个文本字段,顶部的按钮是导航视图工具栏的一部分。我将这个视图定义如下:
NavigationView {
ZStack {
Color("backgroundPrimary")
.ignoresSafeArea()
VStack(alignment: .center) {
ZStack {
ScrollView(showsIndicators: false) {
TextField("Name your workout...", text: $mainTitle)
.padding(.horizontal)
.font(.custom("Helvetica Bold", size: 30))
...
}
}
}
我希望 TextField 放置在靠近顶部的位置,就像 NavigationTitle 的位置一样,但相反,有一个我不知道其起源的间隙。所有堆栈都没有任何垂直填充。我尝试将 .padding(.top, -30)
添加到 TextField,但这会弄乱您可以点击 TextField 以调出键盘的区域。
注意:工具栏以蓝线结束,然后是间隙,然后是文本字段。
有谁知道如何将此 TextField 定位到更靠顶部的位置?
I have a SwiftUI view, the top of which looks like this:
where "name your item" is a TextField and the buttons at the top are part of a NavigationView toolbar. I've defined this view as follows:
NavigationView {
ZStack {
Color("backgroundPrimary")
.ignoresSafeArea()
VStack(alignment: .center) {
ZStack {
ScrollView(showsIndicators: false) {
TextField("Name your workout...", text: $mainTitle)
.padding(.horizontal)
.font(.custom("Helvetica Bold", size: 30))
...
}
}
}
I want the TextField to be positioned nearer to the top, much like the position of a NavigationTitle, but instead there's this gap I don't know the origin of. None of the stacks have any vertical padding. I've tried adding .padding(.top, -30)
to the TextField but this messes up the area that you can tap on the TextField to bring up the keyboard.
Note: The toolbar ends at the blue line, then there's the gap, then there's the TextField.
Does anyone know how I can position this TextField further towards the top?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它仍然是为标题节省空间的
NavigationBar
。添加到您的视图。
It is still the
NavigationBar
saving room for the title. Addto your view.