RectangleView有滑动动画,他的子TextView有旋转动画。我想当 Go! 时, RectangleView 及其子组件(TextView)作为一个整体滑入屏幕(easeInOut)!按下,并且 TextView 永远旋转(线性)。但实际上,子 TextView 与父级分离,旋转(线性)和滑动(线性),并且永远重复。
为什么动画应用到父级效果子级动画?
struct AnimationTestView: View {
@State private var go = false
var body: some View {
VStack {
Button("Go!") {
go.toggle()
}
if go {
RectangleView()
.transition(.slide)
.animation(.easeInOut)
}
}.navigationTitle("Animation Test")
}
}
struct RectangleView: View {
var body: some View {
Rectangle()
.frame(width: 100, height: 100)
.foregroundColor(.pink)
.overlay(TextView())
}
}
struct TextView: View {
@State private var animationRotating: Bool = false
let animation = Animation.linear(duration: 3.0).repeatForever(autoreverses: false)
var body: some …
Run Code Online (Sandbox Code Playgroud)