How to hide and show an Image/View after an animation is done in SwiftUI.
Image(systemName: "arrow.2.circlepath.circle.fill")
.rotationEffect(.degrees(spin ? 360 : 0))
.animation(Animation.easeInOut(duration: 0.8).repeatCount(5))
Use one variable to control the rotation and a second one to control the alpha:
struct ContentView: View {
@State var degrees: Double = 0
@State var alpha: Double = 1
var body: some View {
Image(systemName: "arrow.2.circlepath.circle.fill")
.rotationEffect(.degrees(degrees))
.onAppear(perform: {
withAnimation(Animation.easeInOut(duration: 0.8).repeatCount(5)) {
self.degrees = 360
}
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
self.alpha = 0
}
})
.opacity(alpha)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.