【发布时间】:2019-10-10 04:50:39
【问题描述】:
鉴于以下struct:
struct PeopleList : View {
@State var angle: Double = 0.0
@State var isAnimating = true
var foreverAnimation: Animation {
Animation.linear(duration: 2.0)
.repeatForever()
}
var body: some View {
Button(action: {}, label: {
Image(systemName: "arrow.2.circlepath")
.rotationEffect(Angle(degrees: self.isAnimating ? self.angle : 0.0))
.onAppear {
withAnimation(self.foreverAnimation) {
self.angle += 10.0
}
}
})
}
}
我希望Image 会顺时针旋转并重复,直到self.isAnimating 变为false,尽管它只有一次动画。
【问题讨论】: