Skip to content

Instantly share code, notes, and snippets.

@iAmVishal16
Created April 9, 2023 03:49
Show Gist options
  • Select an option

  • Save iAmVishal16/ac42289b287b97a0ce4132cc6b5d9744 to your computer and use it in GitHub Desktop.

Select an option

Save iAmVishal16/ac42289b287b97a0ce4132cc6b5d9744 to your computer and use it in GitHub Desktop.
//
// SingleTriangleAnimation.swift
// ShapesFun
//
// Created by Vishal Paliwal on 09/04/23.
//
import SwiftUI
struct SingleTriangleAnimation: View {
@State var isAnimating = false
@State var scale = 1
var body: some View {
ZStack {
Color.black
.ignoresSafeArea()
ZStack {
Triangle()
.stroke(lineWidth: 1)
.fill(LinearGradient(colors: [.red, .green, .blue], startPoint: .leading, endPoint: .trailing))
.frame(width: 40, height: 40, alignment: .center)
.scaleEffect(isAnimating ? CGFloat(scale) : 0)
.offset(x: isAnimating ? 100 : -100)
.opacity(isAnimating ? 1 : 0.2)
.animation(Animation.easeOut(duration: 2.5).repeatForever(autoreverses: true), value: isAnimating)
}
}
.onAppear {
isAnimating.toggle()
scale = 2
}
}
}
struct SingleTriangleAnimation_Previews: PreviewProvider {
static var previews: some View {
SingleTriangleAnimation()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment