Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created May 2, 2020 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayfix/6cdfcbffc9294456729d46aab8184ef8 to your computer and use it in GitHub Desktop.
Save rayfix/6cdfcbffc9294456729d46aab8184ef8 to your computer and use it in GitHub Desktop.
A demonstration of using anchor points in SwiftUI
import SwiftUI
struct ContentView: View {
@State private var scale: CGFloat = 1
@State private var angle = Angle(radians: 0)
@State private var color = UIColor.blue
var body: some View {
Image(systemName: "heart.fill")
.resizable()
.frame(width: 100, height: 100)
.rotationEffect(angle, anchor: .center)
.scaleEffect(scale, anchor: .topLeading)
.onTapGesture {
self.scale = 2
self.angle = Angle(radians: .pi)
self.color = UIColor.red
}
.animation(Animation.spring().repeatForever(autoreverses: true))
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment