效果

代码
import SwiftUI
struct ContentView: View {
@State private var animateCircle = false
@State private var isRippling = false
@State private var show = false
var body: some View {
ZStack {
Text("圆形水波纹")
.font(.system(size: 13))
.foregroundColor(Color(red: 153/255, green: 153/255, blue: 153/255))
.frame(width:70, height: 15)
Circle()
.stroke(Color(red: 153/255, green: 153/255, blue: 153/255), lineWidth: 1)
.frame(width: 220, height: 220)
.scaleEffect(animateCircle ? 1 : 0.4)
.opacity(animateCircle ? 0 : 1)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0) {
withAnimation(.linear(duration: 3).repeatForever(autoreverses: false)){
self.animateCircle.toggle()
}
}
}
if show {
Circle()
.stroke(Color(red: 153/255, green: 153/255, blue: 153/255), lineWidth: 1)
.frame(width: 220, height: 220)
.scaleEffect(isRippling ? 1 : 0.4)
.opacity(isRippling ? 0 : 1)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0) {
withAnimation(.linear(duration: 3).repeatForever(autoreverses: false)){
self.isRippling.toggle()
}
}
}
} else {
Text("")
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
withAnimation {
self.show = true
}
}
}
}
}
.padding()
}
}
#Preview {
ContentView()
}