首页 > 如何像iPhone照相机那样使用音量键

如何像iPhone照相机那样使用音量键

查了很多资料,没有找到音量按钮的接口。
各位有没有用过音量键的操作接口?我只需要拿到音量接口按下去弹起来的这个操作,就想UIButton的TouchUpInside一样


音量键的点击检测不是那么轻松就能做到的
不过实现方法还是有的
首先送上来自Stackoverflow的参考代码[1]:

// these 4 lines of code tell the system that "this app needs to play sound/music"
AVAudioPlayer* p = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"photo-shutter.wav"]] error:NULL];
[p prepareToPlay];
[p stop];
[p release];

// these 5 lines of code tell the system that "this window has an volume view inside it, so there is no need to show a system overlay"
[[self.view viewWithTag:54870149] removeFromSuperview];
MPVolumeView* vv = [[MPVolumeView alloc] initWithFrame:CGRectMake(-100, -100, 100, 100)];
[self.view addSubview:vv];
vv.tag = 54870149;
[vv release];

然后送上做了封装的相关开源项目:https://github.com/blladnar/RBVolumeB...
使用方法见:http://ios.biomsoft.com/2011/12/07/ta...

[1]http://stackoverflow.com/questions/83...

【热门文章】
【热门文章】