Haptic feedback with UIFeedbackGenerator

3018
0

Haptic feedback provides tactile responses that enhance user experience. iOS offers three feedback generators: UIImpactFeedbackGenerator for physical impacts with light, medium, or heavy intensities; UINotificationFeedbackGenerator for success, warning, or error outcomes; and UISelectionFeedbackGenerator for selection changes. I call prepare() before triggering feedback to reduce latency—the system spins up the Taptic Engine. Then impactOccurred(), notificationOccurred(), or selectionChanged() triggers the feedback. Haptics complement visual and audio feedback but shouldn't replace them. Overuse diminishes impact and drains battery. I reserve haptics for meaningful interactions like button presses, gestures, and state changes.