如何使 SwiftUI 视图可滚动,使其不与标签栏重叠?
How to make a SwiftUI view scrollable so that it doesn't overlap with tab bar?
所以在我的应用程序中,我有一个看起来像这样的视图
但是,如果您向视频添加 link,则会出现视频播放器,因此标签栏会与表单重叠。
如何使视图可滚动以便滚动到表单底部?
出于某种原因将它放在 ScrollView 中只会使表单消失。
视图代码如下:
VStack {
if let image = self.image {
Image(uiImage: image)
.resizable()
.scaledToFit()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
.onTapGesture {
isIamgePickerShown = true
}
} else {
Image(systemName: "shippingbox.fill")
.resizable()
.scaledToFit()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
.onTapGesture {
isIamgePickerShown = true
}
}
VStack{
if !video.isEmpty {
YouTubeVideoView(videoID: $video)
.frame(maxHeight: UIScreen.main.bounds.height * 0.3)
.cornerRadius(8)
.padding()
}
Form {
Section {
TextField("Name", text: $name)
Picker("Category", selection: $category) {
Text("Food").tag("Food")
Text("Tools").tag("Tools")
Text("Books").tag("Books")
}
DecimalField(value: $amount)
DatePicker("Last Update", selection: $lastUpdated)
TextField("Video URL", text: $video)
}
}
}
}
这里有一个适合你的方法:
VStack {
if let image = self.image {
Image(uiImage: image)
.resizable()
.scaledToFit()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
.onTapGesture {
isIamgePickerShown = true
}
} else {
Image(systemName: "shippingbox.fill")
.resizable()
.scaledToFit()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
.onTapGesture {
isIamgePickerShown = true
}
}
VStack{
Form {
if !video.isEmpty {
YouTubeVideoView(videoID: $video)
.frame(maxHeight: UIScreen.main.bounds.height * 0.3)
.cornerRadius(8)
.padding()
}
Section {
TextField("Name", text: $name)
Picker("Category", selection: $category) {
Text("Food").tag("Food")
Text("Tools").tag("Tools")
Text("Books").tag("Books")
}
DecimalField(value: $amount)
DatePicker("Last Update", selection: $lastUpdated)
TextField("Video URL", text: $video)
}
}
}
}
所以在我的应用程序中,我有一个看起来像这样的视图
但是,如果您向视频添加 link,则会出现视频播放器,因此标签栏会与表单重叠。
如何使视图可滚动以便滚动到表单底部? 出于某种原因将它放在 ScrollView 中只会使表单消失。
视图代码如下:
VStack {
if let image = self.image {
Image(uiImage: image)
.resizable()
.scaledToFit()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
.onTapGesture {
isIamgePickerShown = true
}
} else {
Image(systemName: "shippingbox.fill")
.resizable()
.scaledToFit()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
.onTapGesture {
isIamgePickerShown = true
}
}
VStack{
if !video.isEmpty {
YouTubeVideoView(videoID: $video)
.frame(maxHeight: UIScreen.main.bounds.height * 0.3)
.cornerRadius(8)
.padding()
}
Form {
Section {
TextField("Name", text: $name)
Picker("Category", selection: $category) {
Text("Food").tag("Food")
Text("Tools").tag("Tools")
Text("Books").tag("Books")
}
DecimalField(value: $amount)
DatePicker("Last Update", selection: $lastUpdated)
TextField("Video URL", text: $video)
}
}
}
}
这里有一个适合你的方法:
VStack {
if let image = self.image {
Image(uiImage: image)
.resizable()
.scaledToFit()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
.onTapGesture {
isIamgePickerShown = true
}
} else {
Image(systemName: "shippingbox.fill")
.resizable()
.scaledToFit()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
.onTapGesture {
isIamgePickerShown = true
}
}
VStack{
Form {
if !video.isEmpty {
YouTubeVideoView(videoID: $video)
.frame(maxHeight: UIScreen.main.bounds.height * 0.3)
.cornerRadius(8)
.padding()
}
Section {
TextField("Name", text: $name)
Picker("Category", selection: $category) {
Text("Food").tag("Food")
Text("Tools").tag("Tools")
Text("Books").tag("Books")
}
DecimalField(value: $amount)
DatePicker("Last Update", selection: $lastUpdated)
TextField("Video URL", text: $video)
}
}
}
}