UIPinchGestureRecognizer Tutorial in Swift 3.0

A Gesture Recognizing is one type of touch behaviour on screen of user. By use of that we can finding which type of event on screen. user can do on screen like single tap , double tap , rotate his/her finger on screen , Drag finger , Pinch with finger , Swipe etc. 

There are Six types of Gesture Recognises :


This is tutorial only for UIPinchGestureRecognizer.

Follow the below steps :

Step 1 :  Create Project with File > New > Project > TapGesture-Swift3.

Step 2 :  Adding a simple View on Storyboard. and also give IBOutlet connection of the view.

@IBOutlet weak var viewPinch: UIView!
Step 3 :  Make an instance of the UIPinchGestureRecognizer.

var pinchGesture  = UIPinchGestureRecognizer()
Step 4 :  Initialise the UIPinchGestureRecognizer and adding tap gesture in view. So add the code in ViewDidLoad.

override func viewDidLoad() {
    // PINCH Gesture
    pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(ViewController.pinchedView))
    viewPinch.isUserInteractionEnabled = true
Step 5 :  Method of the PinchGesture.

func pinchedView(sender:UIPinchGestureRecognizer){
    self.view.bringSubview(toFront: viewPinch)
    sender.view?.transform = (sender.view?.transform)!.scaledBy(x: sender.scale, y: sender.scale)
    sender.scale = 1.0

Step 6 :  Output.

Step 7 :  Download UIPinchGestureRecognizer Demo


UIPinchGestureRecognizer Tutorial in Swift 3.0 UIPinchGestureRecognizer Tutorial in Swift 3.0 Reviewed by KIRIT MODI on 22:55:00 Rating: 5

No comments:

Powered by Blogger.