This content originally appeared on HackerNoon and was authored by Vaibhav
Day 3: The earthly vibrations caught me off guard. 💂
\ In the Fourth post of the #30DaysOfSwift series, you'll learn how to implement the haptic feedback with the press of a button or any certain action.
\ Here's the code for you to implement Haptic Feedback with 3 variations.
For those who want to jump into it right away,
\
struct HomeView: View {
let lightFeedback = UIImpactFeedbackGenerator(style: .light) // Change style
let mediumFeedback = UIImpactFeedbackGenerator(style: .medium)
let heavyFeedback = UIImpactFeedbackGenerator(style: .heavy)
var body: some View {
Button("Light Feedback") {
lightFeedback.impactOccurred() // Use this line for haptic feedback
}
Button("Medium Feedback") {
mediumFeedback.impactOccurred()
}
Button("Heavy Feedback") {
heavyFeedback.impactOccurred()
}
}
}
\ Which one hits the right spot? Let me know :)
\ Happy Coding!
This content originally appeared on HackerNoon and was authored by Vaibhav
Vaibhav | Sciencx (2024-10-04T21:48:11+00:00) Haptic Feedback for the Feels – #30DaysOfSwift. Retrieved from https://www.scien.cx/2024/10/04/haptic-feedback-for-the-feels-30daysofswift/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.