1.AudioServicesPlaySystemSound
简单实现手机震动,首先导入AudioToolBox.framework,在需要文件中#import <AudioToolbox/AudioToolbox.h>
第一个
AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_Vibrate, ^{
//播放震动完事调用的块
});
第二个
//短震 3D Touch中的peek震动反馈
AudioServicesPlaySystemSound(1519);
//短震 3D Touch中的pop震动反馈
AudioServicesPlaySystemSound(1520);
//连续三次短震动
AudioServicesPlaySystemSound(1521);
2.UIImpactFeedbackGenerator
UIImpactFeedbackGenerator是iOS10推出的一个类。
typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {
UIImpactFeedbackStyleLight,
UIImpactFeedbackStyleMedium,
UIImpactFeedbackStyleHeavy,
UIImpactFeedbackStyleSoft API_AVAILABLE(ios(13.0)),
UIImpactFeedbackStyleRigid API_AVAILABLE(ios(13.0))
};
UIImpactFeedbackGenerator *impactFeedBack = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
[impactFeedBack prepare];
[impactFeedBack impactOccurred];