如何像iPhone照相机那样使用音量键-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

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

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

展开
收起
a123456678 2016-07-20 10:23:37 1941 0
1 条回答
写回答
取消 提交回答
  • 音量键的点击检测不是那么轻松就能做到的
    不过实现方法还是有的
    首先送上来自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...

    2019-07-17 19:58:43
    赞同 展开评论 打赏
问答排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载