本文介绍了SwiftUI - 动画调整视图框架的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为视图的大小设置动画,以便视图可以使用框架高度来增大或缩小?我需要在两个已知维度之间进行转换.
How do you animate the size of a view, such that the view may grow or shrink using the frame height?I need to transition between two known dimensions.
推荐答案
我不确切知道您需要什么,但这里有一个非常基本的示例,其中 Rectangle
在您点击按钮
:
I don't know exactly what you need but here is a very basic example with a Rectangle
that gets scaled when you tap the Button
:
struct ContentView: View {
@State var animate = false
var body: some View {
VStack {
Button(action: {
withAnimation {
self.animate.toggle()
}
}, label: {
Text("Animate")
})
Rectangle()
.foregroundColor(.blue)
.frame(width: self.animate ? 100 : 150, height: self.animate ? 60 : 90)
}
}
}
请在下一个问题中添加一些代码或编辑问题,以便人们提供更具体的答案.
Please add some code to your next question or edit the question so people can provide a more specific answer.
这篇关于SwiftUI - 动画调整视图框架的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!