其实很简单,主要是系统提供的几种震动方式

主要在这个​​AudioTool.framework​​里

#import <AudioToolbox/AudioToolbox.h>

一般震动

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

普通短震(类似3D Touch的 Peek 反馈 )

AudioServicesPlaySystemSound(1519);

普通短震 (类似3D Touch Pop 反馈)

AudioServicesPlaySystemSound(1520);

连续三次短震

AudioServicesPlaySystemSound(1521);

iOS 10之后提供了一套Objective-C的接口

UIImpactFeedbackGenerator

这个枚举定义震动等级

typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {
UIImpactFeedbackStyleLight,
UIImpactFeedbackStyleMedium,
UIImpactFeedbackStyleHeavy,
UIImpactFeedbackStyleSoft API_AVAILABLE(ios(13.0)),
UIImpactFeedbackStyleRigid API_AVAILABLE(ios(13.0))
};
@interface UIImpactFeedbackGenerator : UIFeedbackGenerator

- (instancetype)initWithStyle:(UIImpactFeedbackStyle)style;

// 调用后立刻开始震动
- (void)impactOccurred;

// 调用后立刻开始震动,伴随着强度等级 0 到 1
- (void)impactOccurredWithIntensity:(CGFloat)intensity API_AVAILABLE(ios(13.0));

@end

使用方式

UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
[generator impactOccurred];