关于ios里的摇一摇以及播放声音和震动
2014-04-29 15:35
155 查看
1.在需要实现摇一摇的controller里面,首先需要在
- (void)viewDidLoad里面初始化
[[UIApplicationsharedApplication]setApplicationSupportsShakeToEdit:YES];
[selfbecomeFirstResponder];
获取摇一摇的动作主要通过下面的三个方法实现的。
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion ==UIEventSubtypeMotionShake )
{
// User was shaking the device. Post a notification named "shake".
[[NSNotificationCenterdefaultCenter] postNotificationName:@"shake"object:self];
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
2.在iOS中,主要使用AudioServicesPlaySystemSound 这个接口来进行声音和震动的播放。
SystemSoundID soundID;
NSString *path = [[NSBundlemainBundle]
pathForResource:@"test"ofType:@"wav"];
AudioServicesCreateSystemSoundID((__bridgeCFURLRef)[NSURLfileURLWithPath:path],
&soundID);
//播放声音
AudioServicesPlaySystemSound (soundID);
//播放震动
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
- (void)viewDidLoad里面初始化
[[UIApplicationsharedApplication]setApplicationSupportsShakeToEdit:YES];
[selfbecomeFirstResponder];
获取摇一摇的动作主要通过下面的三个方法实现的。
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion ==UIEventSubtypeMotionShake )
{
// User was shaking the device. Post a notification named "shake".
[[NSNotificationCenterdefaultCenter] postNotificationName:@"shake"object:self];
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
2.在iOS中,主要使用AudioServicesPlaySystemSound 这个接口来进行声音和震动的播放。
SystemSoundID soundID;
NSString *path = [[NSBundlemainBundle]
pathForResource:@"test"ofType:@"wav"];
AudioServicesCreateSystemSoundID((__bridgeCFURLRef)[NSURLfileURLWithPath:path],
&soundID);
//播放声音
AudioServicesPlaySystemSound (soundID);
//播放震动
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
相关文章推荐
- iOS 实现后台 播放音乐声音 AVAudioPlayer 以及铃声设置(循环播放震动)
- ios播放系统自带音效以及震动
- iOS开发笔记--iphone开发震动与播放声音Demo
- IOS 播放声音和震动
- IOS开发/iphone开发震动与播放声音Demo
- iOS收到Push后播放声音和震动
- IOS开发/iphone开发震动与播放声音
- ios 播放声音和震动
- iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等
- 关于MPMoviePlayerController类播放视频时,外放没有声音的问题(ios)
- 关于iOS录音后播放声音小的问题
- ios播放系统自带音效以及震动
- 摇一摇震动或播放音频案例以及分析详情
- 关于animation PlayState在ios上不起作用, 以及ios前端页面音乐不能自动播放的问题
- IOS开发/iphone开发震动与播放声音Demo
- 关于iOS通过扬声器播放声音的问题。
- iOS 播放声音和震动
- IOS开发/iphone开发震动与播放声音Demo
- ios 播放声音 播放震动
- iOS 播放声音和震动