Created
February 11, 2021 06:26
-
-
Save amosgyamfi/6383d2bdb98abedb810c0dfb41b57b2a 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
// | |
// ContentView.swift | |
// rotateTest | |
// | |
// Created by Amos Gyamfi on 10.2.2021. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
// Initial Animation States | |
@State var rotation = 0.0 | |
@State var scaleXY = 1.0 | |
@State var positionX = -150 | |
@State var objectColor = Color(#colorLiteral(red: 0, green: 0.9914394021, blue: 1, alpha: 1)) | |
var body: some View { | |
Rectangle() | |
.fill(objectColor) | |
.frame(width: 50, height: 50) | |
.rotationEffect(.degrees(rotation)) | |
.scaleEffect(CGFloat(scaleXY)) | |
.offset(x: CGFloat(positionX)) | |
.animation(Animation.easeInOut(duration: 3).repeatForever(autoreverses: true).speed(4)) | |
.onAppear() { | |
// Final Animation States | |
rotation += 360 | |
scaleXY += 1.1 | |
positionX += 250 | |
objectColor = Color(#colorLiteral(red: 1, green: 0.1857388616, blue: 0.5733950138, alpha: 1)) | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
.preferredColorScheme(/*@START_MENU_TOKEN@*/.dark/*@END_MENU_TOKEN@*/) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment