---
title: UIImpactFeedbackGenerator
framework: uikit
role: symbol
role_heading: Class
path: uikit/uiimpactfeedbackgenerator
---

# UIImpactFeedbackGenerator

A concrete feedback generator subclass that creates haptics to simulate physical impacts.

## Declaration

```swift
@MainActor class UIImpactFeedbackGenerator
```

## Overview

Overview Use impact feedback to indicate when an impact occurs. For example, you might trigger impact feedback when a user interface object collides with another object. The following code example shows how to use a pan gesture to drag a square, playing haptic feedback to indicate when the square collides with the edge of its superview. var feedback = UIImpactFeedbackGenerator()

override func viewDidLoad() {     super.viewDidLoad()          // Create an impact feedback object and associate it with the view.     feedback = UIImpactFeedbackGenerator(view: view)          // Draw a basic square and add it to the view hierarchy.     let center = CGPoint(x: view.center.x - 50, y: view.center.y - 50)     let square = UIView(frame: CGRect(origin: center,                                      size: CGSize(width: 100, height: 100)))     square.backgroundColor = .tintColor     view.addSubview(square)          // Add a pan gesture to allow dragging the square.     let panGesture = UIPanGestureRecognizer(target: self, action: #selector(dragSquare(_:)))     square.isUserInteractionEnabled = true     square.addGestureRecognizer(panGesture) }

@objc private func dragSquare(_ sender: UIPanGestureRecognizer) {     guard let square = sender.view else { return }          if sender.state == .began {         // Prepare the feedback object.         feedback.prepare()     }

// Move the square in response to a pan gesture.     let distance = sender.translation(in: view)     square.center = CGPoint(x: square.center.x + distance.x, y: square.center.y + distance.y)     sender.setTranslation(CGPoint.zero, in: view)

// Play impact feedback if the square bumps into the edge of its superview.     if square.hitEdge(of: view) {         feedback.impactOccurred(intensity: 1, at: sender.location(in: view))     } } For more information, read Playing haptic feedback in your app.

## Topics

### Initializing the feedback generator

- [init(style:view:)](uikit/uiimpactfeedbackgenerator/init(style:view:).md)
- [UIImpactFeedbackGenerator.FeedbackStyle](uikit/uiimpactfeedbackgenerator/feedbackstyle.md)

### Reporting impacts

- [impactOccurred()](uikit/uiimpactfeedbackgenerator/impactoccurred().md)
- [impactOccurred(intensity:)](uikit/uiimpactfeedbackgenerator/impactoccurred(intensity:).md)
- [impactOccurred(at:)](uikit/uiimpactfeedbackgenerator/impactoccurred(at:).md)
- [impactOccurred(intensity:at:)](uikit/uiimpactfeedbackgenerator/impactoccurred(intensity:at:).md)

### Deprecated

- [init(style:)](uikit/uiimpactfeedbackgenerator/init(style:).md)

## Relationships

### Inherits From

- [UIFeedbackGenerator](uikit/uifeedbackgenerator.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [UIInteraction](uikit/uiinteraction.md)

## See Also

### Haptic feedback

- [Playing haptic feedback in your app](applepencil/playing-haptic-feedback-in-your-app.md)
- [UIFeedbackGenerator](uikit/uifeedbackgenerator.md)
- [UINotificationFeedbackGenerator](uikit/uinotificationfeedbackgenerator.md)
- [UISelectionFeedbackGenerator](uikit/uiselectionfeedbackgenerator.md)
- [UICanvasFeedbackGenerator](uikit/uicanvasfeedbackgenerator.md)
