Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 =
var body: some View {
Image(systemName: "heart.fill")
.frame(width: 100, height: 100)
.rotationEffect(angle, anchor: .center)
.scaleEffect(scale, anchor: .topLeading)
.onTapGesture {
self.scale = 2
self.angle = Angle(radians: .pi)
self.color =
.animation(Animation.spring().repeatForever(autoreverses: true))
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment