Reputation: 1112
There is a taptic which on long press user get vibrate felling with device for a second.
My device is iPhone 6s version 12.6.1 hope it support the taptic.
@IBAction func onClick(_ sender: Any) {
let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.prepare()
generator.impactOccurred()
// Do Something
}
The above code is not working!
On Button click I want to use the taptic to make user user tap the button! Same thing I would like to use for picker view and other actions where user validate there inputs.
Let me understand is taptic is same small mechanical movementum?
Upvotes: 3
Views: 933
Reputation: 180
This is a list of all the possible types of Haptic Feedback you can use. All of these should work. I don't see anything necessarily wrong with your code might be a connection issue as well. Make sure the button is not disabled, its connected and or not behind something.
Also yes the 6s does support Haptic feedback.
@IBAction func errorButtonTapped(_ sender: UIButton) {
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.error)
}
@IBAction func successButtonTapped(_ sender: UIButton) {
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success)
}
@IBAction func warningButtonTapped(_ sender: UIButton) {
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.warning)
}
@IBAction func lightButtonTapped(_ sender: UIButton) {
let generator = UIImpactFeedbackGenerator(style: .light)
generator.prepare()
generator.impactOccurred()
}
@IBAction func mediumButtonTapped(_ sender: UIButton) {
let generator = UIImpactFeedbackGenerator(style: .medium)
generator.prepare()
generator.impactOccurred()
}
@IBAction func heavyButtonTapped(_ sender: UIButton) {
let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.prepare()
generator.impactOccurred()
}
Upvotes: 2
Reputation: 2522
Make sure this is enabled in settings. If not,
Turn on System Haptic
Go to Settings. Tap on Sounds & Haptics. Scroll all the way down to System Haptics. Toggle this option on.
Upvotes: 0