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! :)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With