【发布时间】:2020-12-21 22:48:13
【问题描述】:
目标:在按下按钮时以展开/折叠样式为部分的外观和消失设置动画。类似于列表中标准行的动画效果。
当前:部分从前缘进入动画,向后缘向外动画。
已尝试:我已尝试对每个部分进行视图翻译,但动画效果并不成功,而且还破坏了行内的选择器。
代码:
struct SectionAnimation: View {
@State var showSection = false
@State var showList = false
var body: some View {
Form {
Button(action: {
withAnimation{
showSection.toggle()
}
}, label: {
Text("Show Section")
})
if showSection {
Section(header: Text("Section One")){
Text("First")
}
Section(header: Text("Section Two")){
Text("Second")
}
Section(header: Text("Section Three")){
Text("Third")
}
}
//How I want it to look
Button(action: {
withAnimation{
showList.toggle()
}
}, label: {
Text("Show List")
})
if showList {
Text("First")
Text("Second")
Text("Third")
}
}
.listStyle(GroupedListStyle())
}
}
【问题讨论】: