在SwiftUI中完成动画后如何隐藏和显示图像/视图。
Image(systemName: "arrow.2.circlepath.circle.fill")
.rotationEffect(.degrees(spin ? 360 : 0))
.animation(Animation.easeInOut(duration: 0.8).repeatCount(5))
答案 0 :(得分:0)
使用一个变量控制旋转,使用第二个变量控制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)
}
}