ios - 如何像iPhone照相机那样使用音量键
PHP中文网
PHP中文网 2017-04-17 11:23:12
[iOS讨论组]

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

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(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...

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号