Учитывая следующее 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: {
self.peopleViewModel.load()
}, 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
, хотя анимируется только один раз.