Get your own website
Demo.swift
ContentView.swift
App.swift
 
import SwiftUI

struct MagnifyClampedDemo: View {
  @State private var scale: CGFloat = 1
  let minS: CGFloat = 0.5
  let maxS: CGFloat = 2.0
  func clamp(_ v: CGFloat) -> CGFloat { min(max(v, minS), maxS) }
  var body: some View {
    Image(systemName: "photo")
      .resizable().scaledToFit().frame(height: 120)
      .scaleEffect(scale)
      .gesture(
        MagnificationGesture()
          .onChanged { value in scale = clamp(value) }
          .onEnded { _ in withAnimation(.easeInOut) { scale = 1 } }
      )
  }
}

                    
import SwiftUI

struct ContentView: View {
  var body: some View { MagnifyClampedDemo() }
}

                    
import SwiftUI

@main
struct MyApp: App {
  var body: some Scene {
    WindowGroup { ContentView() }
  }
}