UIPinchGestureRecognizer

suggest change

Pinches are a two-fingered gesture where the fingers move closer or farther from each other. This gesture is generally used for resizing a view. This sample is Swift 2. It replaces pinchView’s transform with a scale from the identity, using the gesture’s scale since the pinch began. pinchView and label are the sample’s own views. In Swift 3 the state is .changed and the transform is CGAffineTransform(scaleX:y:).

Swift

override func viewDidLoad() {
    super.viewDidLoad()

    // Pinch
    let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(_:)))
    pinchView.addGestureRecognizer(pinchGesture)
}

// Pinch action
func handlePinch(gesture: UIPinchGestureRecognizer) {
    label.text = "Pinch recognized"

    if gesture.state == UIGestureRecognizerState.Changed {
        let transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale)
        pinchView.transform = transform
    }
}

Notes

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents