博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
沉浸式体验:震动反馈
阅读量:7169 次
发布时间:2019-06-29

本文共 1965 字,大约阅读时间需要 6 分钟。

UINotificationFeedbackGenerator

typedef NS_ENUM(NSInteger, UINotificationFeedbackType) {    UINotificationFeedbackTypeSuccess,     UINotificationFeedbackTypeWarning,     UINotificationFeedbackTypeError};- (void)showFeedback{        UINotificationFeedbackGenerator *generator = [[UINotificationFeedbackGenerator alloc] init];    [generator notificationOccurred:UINotificationFeedbackTypeSuccess];}复制代码

UIImpactFeedbackGenerator

typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {    UIImpactFeedbackStyleLight,    UIImpactFeedbackStyleMedium,    UIImpactFeedbackStyleHeavy};- (void)showFeedback{    UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleLight];    [generator prepare];    [generator impactOccurred];}复制代码

UISelectionFeedbackGenerator

用来模拟选择滚轮一类控件时的震动。- (void)showFeedback{    UISelectionFeedbackGenerator *generator = [[UISelectionFeedbackGenerator alloc] init];    [generator selectionChanged];}复制代码

AudioToolbox ( iOS 10 之前 ):

播放系统音

AudioServicesPlaySystemSound (SystemSoundID);/* --- OR --- */ NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/ReceivedMessage.caf"]; // See List of SystemSoundIDsSystemSoundID soundID;AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)fileURL,&soundID);AudioServicesPlaySystemSound(soundID);复制代码

播放自定义音

-(void)playSoundAfterKaoqinSuccess{            NSURL *fileUrl=[[NSBundle mainBundle] URLForResource:@"kaoqin_success.caf" withExtension:nil];        SystemSoundID soundID=0;        AudioServicesCreateSystemSoundID((__bridge CFURLRef)(fileUrl), &soundID);    AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, soundCompleteCallBack, NULL);    AudioServicesPlaySystemSound(soundID);}void soundCompleteCallBack(SystemSoundID soundID, void * clientDate) {        AudioServicesRemoveSystemSoundCompletion(soundID);    AudioServicesDisposeSystemSoundID(soundID);}复制代码

转载于:https://juejin.im/post/5cb684cf51882532a42c0dfd

你可能感兴趣的文章
Windows蓝屏dump文件查看器(转)
查看>>
Java多线程-线程的同步(同步代码块)
查看>>
nyoj322 sort 归并排序,树状数组
查看>>
leetcode -- Partition List
查看>>
timerTask任务定时器
查看>>
leetcode -- Triangle
查看>>
【转载】给VM虚拟机增加硬盘容量
查看>>
中断描述符表(Interrupt Descriptor Table,IDT)
查看>>
机器学习
查看>>
.NET:异常处理的两条“黄金定律”,求批!
查看>>
二叉树的深度
查看>>
android:screenOrientation的说明
查看>>
ubuntu安装日志
查看>>
XMLHTTP使用具体解释
查看>>
FindWindowEx用法
查看>>
Parallel的陷阱
查看>>
asp.net C# int 类型在32/64位环境下取值范围无变化
查看>>
二手房交易流程、交易税费 搜房网
查看>>
安装veloeclipse插件报错解决方案
查看>>
QQ公众号?是的,你没看错!
查看>>