Last active
February 11, 2021 11:53
-
-
Save budidino/47793605c3114a908608411ad5dcd0fe to your computer and use it in GitHub Desktop.
simplified way to call haptic feedback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum HapticStyle { | |
case light | |
case medium | |
case heavy | |
case success | |
case error | |
case warning | |
case selection | |
} | |
func hapticFeedbackWithStyle(_ style: HapticStyle) { | |
if #available(iOS 10.0, *) { | |
if style == .light { | |
let generator = UIImpactFeedbackGenerator(style: .light) | |
generator.impactOccurred() | |
} | |
if style == .medium { | |
let generator = UIImpactFeedbackGenerator(style: .medium) | |
generator.impactOccurred() | |
} | |
if style == .heavy { | |
let generator = UIImpactFeedbackGenerator(style: .heavy) | |
generator.impactOccurred() | |
} | |
if style == .selection { | |
let generator = UISelectionFeedbackGenerator() | |
generator.selectionChanged() | |
} | |
if style == .error { | |
let generator = UINotificationFeedbackGenerator() | |
generator.notificationOccurred(.error) | |
} | |
if style == .warning { | |
let generator = UINotificationFeedbackGenerator() | |
generator.notificationOccurred(.warning) | |
} | |
if style == .success { | |
let generator = UINotificationFeedbackGenerator() | |
generator.notificationOccurred(.success) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment