Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the UIPinchGestureRecognizer with the entire view to zoom the entire screen? Swift 3, IOS

I can't seem to connect my action (pinch gesture) to my view, instead it connects to the viewcontroller. This is everything i have coded in the view controller to test out the code:

import UIKit

class AlertController: UIAlertController {

@IBAction func scaleImage(sender: UIPinchGestureRecognizer) {
    self.view.transform = CGAffineTransformScale(self.view.transform, sender.scale, sender.scale)
    sender.scale = 1
}
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    view.backgroundColor = UIColor.blackColor()
}

override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning()
}

}

All i want to do is zoom into the form i fill out in my app (text boxes - buttons and labels, checkboxes - buttons and labels, background image - image view). I want to be able to zoom into everything at once. Im failing miserably. Please help! :)

like image 601
MontgommeryJR Avatar asked Feb 05 '23 21:02

MontgommeryJR


1 Answers

first make recognizer:

let pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(pinchHandler))

then create handler function:

func pinchHandler(recognizer : UIPinchGestureRecognizer) {

    print ("PINCHING NOW")

    if let view = self.view {
        view.transform = view.transform.scaledBy(x: recognizer.scale, y: recognizer.scale)
        recognizer.scale = 1
    }
}

inside viewDidLoad add recognizer:

pinchGestureRecognizer.addTarget(self, action: #selector(pinchHandler))
view.addGestureRecognizer(pinchGestureRecognizer)
like image 131
Pavel Alexandrovich Ak-01 Avatar answered Feb 07 '23 11:02

Pavel Alexandrovich Ak-01