Skip to content

Instantly share code, notes, and snippets.

@ibrahimyilmaz7
Created November 29, 2020 12:11
Show Gist options
  • Save ibrahimyilmaz7/b3b486067e5b0956225f34c10e8b2f9d to your computer and use it in GitHub Desktop.
Save ibrahimyilmaz7/b3b486067e5b0956225f34c10e8b2f9d to your computer and use it in GitHub Desktop.
AnimatedPlayPauseButton SwiftUI
import SwiftUI
struct AnimatedPlayPauseButton: View {
@Binding var isActive: Bool
var color1: Color { Color("Red") }
var color2: Color { isActive ? Color("Red") : Color("Pink") }
var color3: Color { isActive ? Color("Red") : Color("Yellow") }
var height1: CGFloat { 100 }
var height2: CGFloat { isActive ? 50 : 100 }
var height3: CGFloat { isActive ? 50 : 100 }
var topOffset1: CGFloat { 0 }
var topOffset2: CGFloat { isActive ? 25 : -25 }
var topOffset3: CGFloat { isActive ? -25 : 25 }
var leftOffset1: CGFloat { isActive ? -15 : -25 }
var leftOffset2: CGFloat { isActive ? 35 : 25 }
var leftOffset3: CGFloat { isActive ? 35 : 25 }
var rotate1: Double { 0 }
var rotate2: Double { isActive ? 0 : -60 }
var rotate3: Double { isActive ? 0 : 60 }
var body: some View {
VStack {
ZStack {
Rectangle()
.fill(color1)
.frame(width: 25, height: height1)
.padding()
.rotationEffect(.init(degrees: rotate1))
.offset(x: leftOffset1, y: topOffset1)
Rectangle()
.fill(color2)
.frame(width: 25, height: height2)
.padding()
.rotationEffect(.init(degrees: rotate2))
.offset(x: leftOffset2, y: topOffset2)
Rectangle()
.fill(color3)
.frame(width: 25, height: height3)
.padding()
.rotationEffect(.init(degrees: rotate3))
.offset(x: leftOffset3, y: topOffset3)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment