【发布时间】:2022-07-21 16:12:11
【问题描述】:
struct ContentView: View {
@State private var animationAmount = 1.0
var body: some View {
VStack
{
Stepper("Scale amount", value: $animationAmount.animation(.linear), in: 1...10)
Spacer()
Button("Tap Me")
{
animationAmount += 1
}
.padding(50)
.background(.red)
.foregroundColor(.white)
.clipShape(Circle())
.scaleEffect(animationAmount)
}
}
}
所以我有一个小问题,在这里我创建了一个 Stepper 视图,其值是变量的某种方式的两个绑定,然后我在该绑定上调用了 .animation 方法,据我所知,如果该绑定发生任何变化他们只是得到动画。 我的问题是,是否只有与动画绑定值相关的更改?或者如果这个视图发生了其他一些变化,但巧合的是它们发生在绑定发生变化之前,这些变化也会被动画化吗?
还有一个超级超级小问题,为什么我不能在这个 VStack 中添加一个 if 语句来增加 animationAmount? 喜欢
if animationAmount > 1.0
{
animationAmount += 0.25
}
只是说 () 不符合 View。
【问题讨论】: