美文网首页
iOS开发-UIImpactFeedbackGenerator

iOS开发-UIImpactFeedbackGenerator

作者: 吃不胖的瘦子呀 | 来源:发表于2020-03-30 15:12 被阅读0次
  • 适合环境: iPhone7、iOS10以上
     /*
        typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {//振动模式
                UIImpactFeedbackStyleLight, //轻度
                UIImpactFeedbackStyleMedium,//中度
                UIImpactFeedbackStyleHeavy//重度
            };
        */
     if (@available(iOS 10.0,*)) {
          UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleLight];
          [generator prepare];
          [generator impactOccurred];
     }else{
        // iOS10以前  系统振动加铃声的 用户体验不是很好
        //导入:#import <AudioToolbox/AudioToolbox.h>
       //在需要出发震动的地方写上代码:
       AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//默认震动效果
       //如果想要其他震动效果,可参考:
       // 普通短震,3D Touch 中 Pop 震动反馈
       AudioServicesPlaySystemSound(1520);
       // 普通短震,3D Touch 中 Peek 震动反馈
       AudioServicesPlaySystemSound(1519);
       // 连续三次短震
       AudioServicesPlaySystemSound(1521);
    }

相关文章

网友评论

      本文标题:iOS开发-UIImpactFeedbackGenerator

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