美文网首页
iOS 开发随笔 (系统震动 )

iOS 开发随笔 (系统震动 )

作者: _涼城 | 来源:发表于2019-06-01 21:10 被阅读0次

    系统震动

    导入AudioToolBox.framework
    引入头文件

    #import <AudioToolbox/AudioToolbox.h>
    

    调用代码

    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    

    普通短震(3D Touch 中 Peek 震动反馈)

    AudioServicesPlaySystemSound(1519);
    

    普通短震(3D Touch 中 Pop 震动反馈)

    AudioServicesPlaySystemSound(1520);
    

    连续三次短震

    AudioServicesPlaySystemSound(1521);
    

    UIFeedbackGenerator

    (>iOS 10.0)

    UIFeedbackGenerator 是所有震动反馈的一个抽象基类

    //这是一个可选的方法,当调用此方法时,生成器将在短时间内处于准备状态,可以以较低的延迟触发反馈。
    - (void)prepare;
    

    UIImpactFeedbackGenerator 模拟物理影响。

    typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {
        //轻微震感
        UIImpactFeedbackStyleLight,
        //中度震感
        UIImpactFeedbackStyleMedium,
        //重度震感
        UIImpactFeedbackStyleHeavy
    };
    //初始化方法
    - (instancetype)initWithStyle:(UIImpactFeedbackStyle)style;
    // 调用震动
    - (void)impactOccurred;
    

    UINotificationFeedbackGenerator 传达成功,失败和警告。

    typedef NS_ENUM(NSInteger, UINotificationFeedbackType) {
        UINotificationFeedbackTypeSuccess,
        UINotificationFeedbackTypeWarning,
        UINotificationFeedbackTypeError
    };
    
    
    //触动震动提醒成功、失败、警告
    - (void)notificationOccurred:(UINotificationFeedbackType)notificationType;
    

    UISelectionFeedbackGenerator指示选择的更改。

    //例如 选择器UIPicker的震动反馈
    - (void)selectionChanged;
    

    相关文章

      网友评论

          本文标题:iOS 开发随笔 (系统震动 )

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