Created
February 6, 2023 00:15
-
-
Save amosgyamfi/6928737c432729ef60d51fb5b729832c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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