将水平卷轴移动到顶级Swiftui
我正在尝试将图像移至顶部中的图像。他们目前在底部。我尝试添加navigationView
,.padding()
,spacer()
,添加zstack
作为父母HSTACK
和hstack(Alignment:.top)
。我被困了3天。
是否可以将水平滚动浏览在顶部?
这是代码:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollView(.horizontal) {
HStack(spacing: 15) {
Group {
Image("OutdoorDining1")
.frame(width: 230, height: 148)
Image("EatVegan")
.frame(width: 230, height: 148)
Image("CityView")
.frame(width: 230, height: 148)
Image("LiveMusic")
.frame(width: 230, height: 148)
}
Group {
Image("Seafood")
.frame(width: 230, height: 148)
Image("Blackowned")
.frame(width: 230, height: 148)
Image("Hookah")
.frame(width: 230, height: 148)
Image("OpenTilLate")
.frame(width: 230, height: 148)
}
Group {
Image("CentralAmerica")
.frame(width: 230, height: 148)
Image("Asian")
.frame(width: 230, height: 148)
Image("Mediterranean")
.frame(width: 230, height: 148)
}
Group {
Image("Steakhouses")
.frame(width: 230, height: 148)
Image("Kosher")
.frame(width: 230, height: 148)
}
I am trying to move the images in Horizontal ScrollView up top. They are currently at the bottom. I have tried adding NavigationView
, .padding()
, Spacer()
, Adding a ZStack
as a parent to HStack
, and HStack(alignment: .top)
. I have been stuck for 3 days.
Is it possible to have Horizontal ScrollView up top?
Here is the code:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollView(.horizontal) {
HStack(spacing: 15) {
Group {
Image("OutdoorDining1")
.frame(width: 230, height: 148)
Image("EatVegan")
.frame(width: 230, height: 148)
Image("CityView")
.frame(width: 230, height: 148)
Image("LiveMusic")
.frame(width: 230, height: 148)
}
Group {
Image("Seafood")
.frame(width: 230, height: 148)
Image("Blackowned")
.frame(width: 230, height: 148)
Image("Hookah")
.frame(width: 230, height: 148)
Image("OpenTilLate")
.frame(width: 230, height: 148)
}
Group {
Image("CentralAmerica")
.frame(width: 230, height: 148)
Image("Asian")
.frame(width: 230, height: 148)
Image("Mediterranean")
.frame(width: 230, height: 148)
}
Group {
Image("Steakhouses")
.frame(width: 230, height: 148)
Image("Kosher")
.frame(width: 230, height: 148)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗨,克里斯蒂娜,欢迎来!您可以使用Chrisr的建议
VSTACK
+spacer()
- 它是有效的,但是如果您构建了更复杂的UI并想添加scrollview(.vertical)
以及更多视图使用下一个层次结构Hi Christina and welcome to SO! You can use ChrisR's suggestion
VStack
+Spacer()
- it's works, but if you building more complex UI and want to addScrollView(.vertical)
and more views use next hierarchy