-
Notifications
You must be signed in to change notification settings - Fork 520
Labels
Description
On iOS 10.0+, iPadOS 10.0+ and Mac Catalyst 13.1+, it is possible for iPhones and iPads to generate different type of viberations, Not just a fixed 400ms one. Just Mapping seconds to UIFeedbackGenerator's subclasses like this:
if (@available(iOS 10.0, *)) {
// iOS 10.0 and above
UIImpactFeedbackGenerator *impact = nil;
if (seconds >= 0.5 && seconds < 1.5) {
impact = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
} else if (seconds >= 1.5 && seconds < 2.5) {
impact = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
} else if (seconds >= 2.5) {
impact = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
} else {
return;
}
[impact impactOccurred];
return;
}