如何在 SwiftUI 中将视图(即列表)转换为从屏幕上的某个点出现?
我有一个占据屏幕顶部 60% 的列表。我希望列表在转换过程中从 60% 的底部滑入,而不是从手机屏幕的底部滑入,从而实现动画效果。如果你看一下我的代码,你就会明白我在说什么......
struct ContentView: View {
let controls = ["backward.fill", "play.fill", "forward.fill"]
@State private var showingList = false
var body: some View {
GeometryReader { geo in
VStack {
Group {
if showingList {
List(0..<50) {
Text("\($0)")
}
.transition(.move(edge: .bottom))
} else {
Spacer()
}
}
.frame(maxWidth: geo.size.width, maxHeight: geo.size.height * 0.6)
//I want the list to slide in from the bottom of the top frame that takes 60% of the height.
HStack {
ForEach(controls, id: \.self) {
Image(systemName: $0)
.foregroundColor(.white)
}
}
.frame(maxWidth: geo.size.width, maxHeight: geo.size.height * 0.4)
.onTapGesture {
withAnimation {
showingList.toggle()
}
}
}
//I don't want the view to slide in from the bottom of the phone right here
}
}
}
I have a list that occupies 60% of the top of the screen. I want the list to animate by sliding in from the bottom of that 60% during the transition instead of the bottom of the phone screen. If you take a look at my code, you will get an idea on what im talking about...
struct ContentView: View {
let controls = ["backward.fill", "play.fill", "forward.fill"]
@State private var showingList = false
var body: some View {
GeometryReader { geo in
VStack {
Group {
if showingList {
List(0..<50) {
Text("\($0)")
}
.transition(.move(edge: .bottom))
} else {
Spacer()
}
}
.frame(maxWidth: geo.size.width, maxHeight: geo.size.height * 0.6)
//I want the list to slide in from the bottom of the top frame that takes 60% of the height.
HStack {
ForEach(controls, id: \.self) {
Image(systemName: $0)
.foregroundColor(.white)
}
}
.frame(maxWidth: geo.size.width, maxHeight: geo.size.height * 0.4)
.onTapGesture {
withAnimation {
showingList.toggle()
}
}
}
//I don't want the view to slide in from the bottom of the phone right here
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,您希望列表在出现时隐藏在控件后面。您可以尝试在控件后面添加背景:
If I understand you correctly, you want the list to be hidden behind your controls while it appears. You can try adding a background behind the controls: