Created
May 2, 2020 18:46
-
-
Save rayfix/6cdfcbffc9294456729d46aab8184ef8 to your computer and use it in GitHub Desktop.
A demonstration of using anchor points in SwiftUI
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
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