Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created May 2, 2020 18:46
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