<!--
{
  "documentType" : "article",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/handling-pinch-gestures",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Handling pinch gestures"
}
-->

# Handling pinch gestures

Track the distance between two fingers and use that information to scale or zoom your content.

## Discussion

A pinch gesture is a continuous gesture that tracks the distance between the first two fingers that touch the screen. Use the [`UIPinchGestureRecognizer`](/documentation/UIKit/UIPinchGestureRecognizer) class to detect pinch gestures.

You can attach a gesture recognizer in one of these ways:

- Programmatically. Call the [`addGestureRecognizer(_:)`](/documentation/UIKit/UIView/addGestureRecognizer(_:)) method of your view.
- In Interface Builder. Drag the appropriate object from the library and drop it onto your view.

![A diagram demonstrating how two fingers can start a pinch gesture.](images/com.apple.uikit/handling-pinch-gestures-1~dark@2x.png)

A pinch gesture recognizer reports changes to the distance between two fingers touching the screen. Pinch gestures are continuous, so your action method is called each time the distance between the fingers changes. The distance between the fingers is reported as a scale factor. At the beginning of the gesture, the scale factor is `1.0`. As the distance between the two fingers increases, the scale factor increases proportionally. Similarly, the scale factor decreases as the distance between the fingers decreases. Pinch gestures are used most commonly to change the size of objects or content onscreen. For example, map views use pinch gestures to change the zoom level of the map.

A pinch gesture recognizer enters the [`UIGestureRecognizer.State.began`](/documentation/UIKit/UIGestureRecognizer/State-swift.enum/began) state only after the distance between the two fingers changes for the first time. After that initial change, subsequent changes to the distance put the gesture recognizer into the [`UIGestureRecognizer.State.changed`](/documentation/UIKit/UIGestureRecognizer/State-swift.enum/changed) state and update the scale factor. When a person’s fingers lift from the screen, the gesture recognizer enters the [`UIGestureRecognizer.State.ended`](/documentation/UIKit/UIGestureRecognizer/State-swift.enum/ended) state.

> Important:
> Take care when applying a pinch gesture recognizer’s scale factor to your content, or you might get unexpected results. Because your action method may be called many times, you can’t simply apply the current scale factor to your content. If you multiply each new scale value by the current value of your content, which has already been scaled by previous calls to your action method, your content will grow or shrink exponentially. Instead, cache the original value of your content, apply the scale factor to that original value, and apply the new value back to your content. Alternatively, reset the ``doc://com.apple.uikit/documentation/UIKit/UIPinchGestureRecognizer/scale`` factor to `1.0` after applying each new change.

The following code demonstrates how to resize a view linearly using a pinch gesture recognizer. This action method applies the current scale factor to the view’s transform and then resets the gesture recognizer’s [`scale`](/documentation/UIKit/UIPinchGestureRecognizer/scale) property to `1.0`. Resetting the scale factor causes the gesture recognizer to report only the amount of change since the value was reset, which results in linear scaling of the view.

```swift
@IBAction func scalePiece(_ gestureRecognizer: UIPinchGestureRecognizer) {
    guard gestureRecognizer.view != nil else { return }

    if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
        gestureRecognizer.view?.transform = (gestureRecognizer.view?.transform.
                    scaledBy(x: gestureRecognizer.scale, y: gestureRecognizer.scale))!
        gestureRecognizer.scale = 1.0
    }
}
```

If the code for your pinch gesture recognizer isn’t called, or isn’t working correctly, check to see if the following conditions are true, and make corrections as needed:

- The [`isUserInteractionEnabled`](/documentation/UIKit/UIView/isUserInteractionEnabled) property of the view is set to <doc://com.apple.documentation/documentation/Swift/true>. Image views and labels set this property to <doc://com.apple.documentation/documentation/Swift/false> by default.
- At least two fingers are touching the screen.
- You’re applying scale factors to your content correctly. Exponential growth of a value happens when you simply apply the scale factor to the current value.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)