我怎样才能让 spring() 动画正确
How can i get the spring() animation right
单击按钮时,我希望我的 MapScreen 从底部“滑入”。所以我使用了.annimation(spring())。这曾经有效,现在我得到了动画弃用(需要一个值)。我如何在 spring() 动画上解决这个问题。
是否可以在 if showMapScreen 开关上设置 WithAnimation?
struct ContentView: View {
@State private var showMapScreen = false
var body: some View {
ZStack {
Color.white
.ignoresSafeArea()
VStack {
Button("Show Map") {
showMapScreen.toggle()
}
}
if showMapScreen {
MapScreen()
.padding(.top, 400)
.transition(.move(edge: .bottom))
.animation(spring(), value:???)
}
}
}
}
//第二个视图
struct MapScreen: View {
@State private var mapRegion = MKCoordinateRegion(center:
CLLocationCoordinate2D(latitude: 51.5, longitude: -0.12), span:
MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2))
var body: some View{
ZStack(alignment:.top) {
Color.white
//handle for dragging
Capsule()
.frame(width:40, height:10)
.zIndex(2.0)
Map(coordinateRegion: $mapRegion)
}
.cornerRadius(30)
.edgesIgnoringSafeArea(.bottom)
}
}
将其移动到容器中并将动画放入容器中以使其内容具有动画效果,例如
VStack {
if showMapScreen {
MapScreen()
.padding(.top, 400)
.transition(.move(edge: .bottom))
}
}
.animation(spring(), value: showMapScreen) // << here !!
单击按钮时,我希望我的 MapScreen 从底部“滑入”。所以我使用了.annimation(spring())。这曾经有效,现在我得到了动画弃用(需要一个值)。我如何在 spring() 动画上解决这个问题。
是否可以在 if showMapScreen 开关上设置 WithAnimation?
struct ContentView: View {
@State private var showMapScreen = false
var body: some View {
ZStack {
Color.white
.ignoresSafeArea()
VStack {
Button("Show Map") {
showMapScreen.toggle()
}
}
if showMapScreen {
MapScreen()
.padding(.top, 400)
.transition(.move(edge: .bottom))
.animation(spring(), value:???)
}
}
}
}
//第二个视图
struct MapScreen: View {
@State private var mapRegion = MKCoordinateRegion(center:
CLLocationCoordinate2D(latitude: 51.5, longitude: -0.12), span:
MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2))
var body: some View{
ZStack(alignment:.top) {
Color.white
//handle for dragging
Capsule()
.frame(width:40, height:10)
.zIndex(2.0)
Map(coordinateRegion: $mapRegion)
}
.cornerRadius(30)
.edgesIgnoringSafeArea(.bottom)
}
}
将其移动到容器中并将动画放入容器中以使其内容具有动画效果,例如
VStack {
if showMapScreen {
MapScreen()
.padding(.top, 400)
.transition(.move(edge: .bottom))
}
}
.animation(spring(), value: showMapScreen) // << here !!