美文网首页
iOS开发 振动实现

iOS开发 振动实现

作者: 清风_____ | 来源:发表于2020-04-23 19:01 被阅读0次

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];

相关文章

网友评论

      本文标题:iOS开发 振动实现

      本文链接:https://www.haomeiwen.com/subject/dzfzihtx.html