General Middleware
Enable Pinch Zoom in your photos in Swift Xcode
- Open Xcode and create a new project
- Go to Main.storyboard, and add an UIImageView Object and align it to the center of the screen
- Select an Image from your Assets and add it to the UIImageView in the Main.storyboard
- Add a UIPinchGestureRecognizer object and drop it into the UIImageView created in the previous step
- Connect the UIImageView in Main.storyboard to the IBOutlet of the ViewController
- Connect the UIPinchGestureRecognizer to a IBOutlet and an IBAction of the ViewController
- Below is the Code for the ViewController
//
// ViewController.swift
// PhotoZoom
//
// Created by Animesh Banerjee on 30/4/21.
//
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet var pinchGesture: UIPinchGestureRecognizer!
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
imageView.isUserInteractionEnabled = true
}
@IBAction func addgesture(_ sender: Any) {
guard let gestureView = pinchGesture.view else {
return
}
gestureView.transform = gestureView.transform.scaledBy(x: pinchGesture.scale, y: pinchGesture.scale)
pinchGesture.scale = 1.0
}
}