Haptic Feedback for the Feels - #30DaysOfSwift
2024-10-5 05:48:11 Author: hackernoon.com(查看原文) 阅读量:6 收藏

Read on Terminal Reader

Open TLDRtldt arrow

Too Long; Didn't Read

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.Day 3: The earthly vibrations caught my off guard.

featured image - Haptic Feedback for the Feels - #30DaysOfSwift

Vaibhav HackerNoon profile picture

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.

Image description

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!


文章来源: https://hackernoon.com/haptic-feedback-for-the-feels-30daysofswift?source=rss
如有侵权请联系:admin#unsafe.sh