前段时间看了很多App有用到这个效果呢,比如点击tableViewCell的时候有时候会感觉手机有震动一下,还有3DTouch的时候也有类似的效果。于是就找到了这么个API。使用方式非常简单:
//震动反馈
/*
typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {
UIImpactFeedbackStyleLight,
UIImpactFeedbackStyleMedium,
UIImpactFeedbackStyleHeavy
};
*/
if (@available(iOS 10.0,*)) {
UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleLight];
[generator prepare];
[generator impactOccurred];
}
UIImpactFeedbackStyle表示触感力道。