Skip to content

Instantly share code, notes, and snippets.

@0xack13
Created March 4, 2026 06:35
Show Gist options
  • Select an option

  • Save 0xack13/1fcf71b7dec2ea65fa0f93880198d12c to your computer and use it in GitHub Desktop.

Select an option

Save 0xack13/1fcf71b7dec2ea65fa0f93880198d12c to your computer and use it in GitHub Desktop.
swiftui examples
import SwiftUI
struct AnimationView: View {
@State private var isRecording = false
@State private var pulseScale: CGFloat = 1.0
@State private var pulseOpacity: Double = 0.6
var body: some View {
ZStack {
// Pulse rings
ForEach(0..<40) { i in
Circle()
.stroke(Color.red.opacity(0.95 - Double(i) * 0.12), lineWidth: 2)
.frame(width: 72 + CGFloat(i + 1) * 22,
height: 72 + CGFloat(i + 1) * 22)
.scaleEffect(pulseScale)
.opacity(pulseOpacity)
}
// Button
Circle()
.fill(Color.red)
.frame(width: 72, height: 72)
.shadow(color: Color.red.opacity(0.55), radius: 14, y: 5)
.overlay(
RoundedRectangle(cornerRadius: isRecording ? 5 : 36)
.fill(.white)
.frame(width: isRecording ? 25 : 32, height: isRecording ? 25 : 32)
.animation(.spring(response: 0.35, dampingFraction: 0.65), value: isRecording)
)
.onTapGesture { toggle() }
}
.onChange(of: isRecording) { _, recording in
if recording {
withAnimation(.easeOut(duration: 1.1).repeatForever(autoreverses: false)) {
pulseScale = 3.65
pulseOpacity = 0
}
} else {
withAnimation(.spring()) {
pulseScale = 1.0
pulseOpacity = 0.6
}
}
}
}
private func toggle() {
isRecording.toggle()
}
}
#Preview {
AnimationView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.black)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment