如何使动画在SwiftUI中的ScrollView中工作? SwiftUI中的手风琴样式动画

时间:2019-09-23 07:08:27

标签: ios swift swiftui

我正在尝试使用SwiftUI用动画构建手风琴样式视图。但是如果将动画包装到ScrollView中,动画将无法正常工作。下面是我要尝试的代码。

implements

下面是我面临的问题的屏幕截图。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

要使其具有动画效果,请将self.isPressed.toggle()包裹在withAnimation闭包中。

Button("Press") { withAnimation { self.isPressed.toggle() } }

enter image description here