Created
April 9, 2023 03:49
-
-
Save iAmVishal16/ac42289b287b97a0ce4132cc6b5d9744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // | |
| // 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