How to add haptics and vibrations to Xcode project | Continued Learning #10
Notification
과 Impact
가 존재한다. (커스텀도 존재한다) func notification(type: UINotificationFeedbackGenerator.FeedbackType) {
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(type)
}
func impact(style: UIImpactFeedbackGenerator.FeedbackStyle) {
let generator = UIImpactFeedbackGenerator(style: style)
generator.impactOccurred()
}
import SwiftUI
class HapticManager {
static let instance = HapticManager()
private init() {}
func notification(type: UINotificationFeedbackGenerator.FeedbackType) {
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(type)
}
func impact(style: UIImpactFeedbackGenerator.FeedbackStyle) {
let generator = UIImpactFeedbackGenerator(style: style)
generator.impactOccurred()
}
}
struct HapticsBootCamp: View {
let hapticManager = HapticManager.instance
var body: some View {
VStack(spacing: 20) {
Button("SUCCESS") { hapticManager.notification(type: .success) }
Button("WARNING") { hapticManager.notification(type: .warning) }
Button("ERROR") { hapticManager.notification(type: .error) }
Divider()
Button("SOFT") { hapticManager.impact(style: .soft) }
Button("LIGHT") { hapticManager.impact(style: .light) }
Button("MEDIUM") { hapticManager.impact(style: .medium) }
Button("RIGID") { hapticManager.impact(style: .rigid) }
Button("HEAVY") { hapticManager.impact(style: .heavy) }
}
}
}