ABVolumeControl 0.1.1

ABVolumeControl 0.1.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年2月

Andrew Boryk维护。




示例

要运行示例项目,请克隆仓库,并先从 Example 目录运行 pod install

截图

描述

一个自定义音量控制器,用于替换 MPVolumeView。ABVolumeControl 提供了多种样式,并提供了一个委托用于创建自定义的音量滑块。

要求

  • 需要 iOS 8.0 或更高版本
  • 要求自动引用计数(ARC)
  • 需要 MediaPlayer 框架

安装

ABVolumeControl 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中

pod "ABVolumeControl"

初始化

通过在 ABVolumeControl 的共享管理器上调用 'setVolumeControlStyle:' 来初始化 ABVolumeControl。ABVolumeControl 的样式有几种不同的设置。如果没有设置控制的样式,将不会有可见的 ABVolumeControl。

// The first style for an ABVolumeControl is minimal, which is a 2px-tall bar that is visible at the top of the screen above the UIStatusBar.
[[ABVolumeControl sharedManager] setVolumeControlStyle:ABVolumeControlStyleMinimal];

// Set the ABVolumeControl style to Status Bar style. This style is similar to the 'minimal' style, with added space between the control and the top of the screen, allowing the control to cover the UIStatusBar. This makes the control more visible.
[[ABVolumeControl sharedManager] setVolumeControlStyle:ABVolumeControlStyleStatusBar];

// One can remove the custom ABVolumeControl by setting the volumeControlStyle to ABVolumeControlStyleNone. This would bring back the original MPVolumeView.
[[ABVolumeControl sharedManager] setVolumeControlStyle:ABVolumeControlStyleNone];

// Setting the volumeControlStyle to custom ensures that the MPVolumeView is not shown, and no ABVolumeControl appears. There is a delegate available to listen to changes in the user's volume, and communicate changes in a custom volume slider to the rest of the application.
[[ABVolumeControl sharedManager] setVolumeControlStyle:ABVolumeControlStyleCustom];

定制

有设置可用于修改 ABVolumeControl 的外观,使更改颜色变得简单。

// Changing the theme of the ABVolumeControl allows for easy access to modifying the appearance of the ABVolumeControl depending on it's surroundings (Dark backgrounds vs Light backgrounds)
[[ABVolumeControl sharedManager] setControlTheme: ABVolumeControlDarkTheme];

除了设置控制主题,暗色和亮色主题的强调颜色可以单独设置。

// Changes the accent color associated with the ABVolumeControlDarkTheme theme
[[ABVolumeControl sharedManager] setDefaultDarkColor:[UIColor blueColor]];

// Changes the accent color associated with the ABVolumeControlLightTheme theme
[[ABVolumeControl sharedManager] setDefaultLightColor:[UIColor yellowColor]];

可以通过在共享管理器上调用 'setVolumeLevel:' 方法来程序性地调整用户设备的音量。

[[ABVolumeControl sharedManager] setVolumeLevel:0.5f];

可以通过使用 'hideVolumeControl' 和 'showVolumeControl' 方法手动隐藏和显示音量栏。'hideVolumeControl' 立即隐藏 ABVolumeControl 并确保在被调用后的 1 秒内不会显示。'showVolumeControl' 通过动画显示 ABVolumeControl。还有一个变量 'volumeControlHidden',用于设置 ABVolumeControl 不会无限期地显示,除非指定了其他操作。

// Ensures that the ABVolumeControl will not be shown for 1 second time, and hides it immediately
[[ABVolumeControl sharedManager] hideVolumeControl];

// Displays the ABVolumeControl with animation
[[ABVolumeControl sharedManager] showVolumeControl];

// Makes sure that the ABVolumeControl will not be displayed until specified otherwise.
[[ABVolumeControl sharedManager] setVolumeControlHidden: YES];

委托

当使用ABVolumeControlStyleCustom或简单希望容易地监视用户设备的当前音量级别时,可以使用以下委托

// Set delegate for the volume control to be used for custom volume sliders
[[ABVolumeControl sharedManager] setVolumeDelegate:self];

// Volume did change in the ABVolumeControl to the value 'volumePercentage' (0.0 - 1.0)
- (void)control:(ABVolumeControl *)control didChangeVolume:(CGFloat)volumePercentage;

此外,当要知道音量控制将/已显示和消失时,已提供委托方法。这些方法在ABVolumeControlStyleMinimal和ABVolumeControlStyleStatusBar中调用。

// ABVolumeControl will be displayed
- (void)controlWillPresent:(ABVolumeControl *)control;

// ABVolumeControl was displayed
- (void)controlDidPresent:(ABVolumeControl *)control;

// ABVolumeControl will be dismissed
- (void)controlWillDismiss:(ABVolumeControl *)control;

// ABVolumeControl was dismissed
- (void)controlDidDismiss:(ABVolumeControl *)control;

作者

andrewboryk,[email protected]

在Twitter上联系我 @TrepIsLife alt text

许可证

ABVolumeControl在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。