Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created February 6, 2023 00:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amosgyamfi/6928737c432729ef60d51fb5b729832c to your computer and use it in GitHub Desktop.
Save amosgyamfi/6928737c432729ef60d51fb5b729832c to your computer and use it in GitHub Desktop.
//
// FluidMusicButons.swift
// EnterSwiftUIAnimations
import SwiftUI
struct FluidMusicButons: View {
@State private var isPlaying = false
@State private var transparency: Double = 0.0
var body: some View {
Button {
isPlaying.toggle()
transparency = 0.6
withAnimation(.easeOut(duration: 0.2)) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
transparency = 0.0
}
}
} label: {
ZStack {
Circle()
.frame(width: 90, height: 90)
.opacity(transparency)
Image(systemName: "pause.fill")
.font(.system(size: 64))
.scaleEffect(isPlaying ? 1 : 0)
.opacity(isPlaying ? 1 : 0)
.animation(.interpolatingSpring(stiffness: 170, damping: 15), value: isPlaying)
Image(systemName: "play.fill")
.font(.system(size: 64))
.scaleEffect(isPlaying ? 0 : 1)
.opacity(isPlaying ? 0 : 1)
.animation(.interpolatingSpring(stiffness: 170, damping: 15), value: isPlaying)
}
}
}
}
struct FluidMusicButons_Previews: PreviewProvider {
static var previews: some View {
FluidMusicButons()
.preferredColorScheme(.dark)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment