Skip to content

Instantly share code, notes, and snippets.

@kwylez
Created February 28, 2022 15:56
Show Gist options
  • Save kwylez/371c1fd6be58b2f2df6588b470932951 to your computer and use it in GitHub Desktop.
Save kwylez/371c1fd6be58b2f2df6588b470932951 to your computer and use it in GitHub Desktop.
//
// Trigger_Gesture_Magnification.swift
// SwiftUIAnimations
//
// Created by Mark Moeykens on 11/5/19.
// Copyright © 2019 Mark Moeykens. All rights reserved.
//
import SwiftUI
struct Trigger_Gesture_Magnification: View {
@GestureState private var scale: CGFloat = 1.0
@State private var endScale: CGFloat = 1.0
private var magnificationScale: CGFloat {
return max(1.0, endScale) * scale
}
var body: some View {
VStack(spacing: 20) {
TitleText("Trigger")
SubtitleText("Magnification Gesture")
BannerText("Animation can smooth out the magnification of views.",
backColor: .green)
Text("Zoom In")
Spacer()
Image("castle")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 200)
.scaleEffect(magnificationScale)
.gesture(MagnificationGesture()
.updating($scale, body: { (value, scale, transaction) in
scale = value
})
.onEnded({ (value) in
endScale *= value
})
)
.animation(.default, value: magnificationScale) // Smooth the zooming in and out
Spacer()
}
.font(.title)
}
}
struct Trigger_Gesture_Magnification_Previews: PreviewProvider {
static var previews: some View {
Trigger_Gesture_Magnification()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment