DLVolumeButtons
示例
运行示例项目,请先克隆代码库,然后从示例目录中运行 pod install
## 要求
安装
DLVolumeButtons 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'DLVolumeButtons'
使用方法
需要强持有创建的对象
@property (nonatomic, strong) DLVolumeButtons *volumeButtons;
创建方法
- (void)setupVolumeButtons
{
if (!self.volumeButtons) {
__weak typeof(self) weakSelf = self;
self.volumeButtons = [DLVolumeButtons volumeButtonHandlerWithUpBlock:^{
NSLog(@"点击了 上音量键");
[weakSelf showAlertWithText:@"点击了 上音量键"];
} downBlock:^{
NSLog(@"点击了 下音量键");
[weakSelf showAlertWithText:@"点击了 下音量键"];
}];
if ([self.volumeButtons respondsToSelector:@selector(changeVolumeSuperView:)]) {
[self.volumeButtons changeVolumeSuperView:self.view];
}
}
}
灵活开关 是否替换系统音量view
- (IBAction)valueChanged:(UISegmentedControl *)sender {
if (sender.selectedSegmentIndex) {
// 开
[self.volumeButtons startHandler:YES];
} else {
// 关
[self.volumeButtons stopHandler];
}
}
## 注意
建议最好将当前可视窗口传给 DLVolumeButton,代码里面创建了一个 MPVolumeView 音量view,默认放在最前面的 window里,当你替换了音量键事件后,没有将新创建 音量view 放在当前 self.view上,有可能替换了事件但是还是会出现系统改音量的窗口。
[self.volumeButtons changeVolumeSuperView:self.view];
作者
daiquanxiang, [email protected]
许可
DLVolumeButtons遵循MIT许可协议。更多信息请参阅LICENSE文件。