Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// 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