1.AudioServicesPlaySystemSound
簡單實現手機震動,首先導入AudioToolBox.framework,在需要文件中#import <AudioToolbox/AudioToolbox.h>
第一個
AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_Vibrate, ^{
//播放震動完事調用的塊
});
第二個
//短震 3D Touch中的peek震動反饋
AudioServicesPlaySystemSound(1519);
//短震 3D Touch中的pop震動反饋
AudioServicesPlaySystemSound(1520);
//連續(xù)三次短震動
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];