NAKPlaybackIndicatorView 0.1.1

NAKPlaybackIndicatorView 0.1.1

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布上次发布2017 年 8 月

Yuji Nakayama 维护。




  • 作者:
  • Yuji Nakayama

Music.app

NAKPlaybackIndicatorView 是一个模拟 iOS 中 Music.app 音乐播放指示器功能的视图。它包含一些垂直条,它们会随机振荡。

需要 iOS 8.0 或更高版本。

尝试演示应用

您可以使用 CocoaPods 立即尝试演示应用

# This will open an Xcode workspace
$ pod try NAKPlaybackIndicatorView

在打开的工作区中,选择 演示 方案并运行。

安装

NAKPlaybackIndicatorView 通过 CocoaPods 提供,要安装它,只需在您的 Podfile 中添加以下行

pod 'NAKPlaybackIndicatorView'

然后运行 pod install

基本使用

这里是一个基本示例

#import <NAKPlaybackIndicatorView/NAKPlaybackIndicatorView.h>

- (void)viewDidLoad
{
    [super viewDidLoad];

    NAKPlaybackIndicatorViewStyle *style = [NAKPlaybackIndicatorViewStyle iOS7Style];
    NAKPlaybackIndicatorView *indicator = [[NAKPlaybackIndicatorView alloc] initWithStyle:style];
    [self.view addSubview:indicator];
    [indicator sizeToFit];

    // Initially the `state` property is NAKPlaybackIndicatorViewStateStopped
    // and the `hidesWhenStopped` property is YES.
    // Thus, the view is hidden at this time.

    // The view appears and the bars start animation.
    indicator.state = NAKPlaybackIndicatorViewStatePlaying;

    // The bars stop animation and become idle.
    indicator.state = NAKPlaybackIndicatorViewStatePaused;

    // The view becomes hidden.
    indicator.state = NAKPlaybackIndicatorViewStateStopped;
}

您可以在代码和 Storyboard 中使用 NAKPlaybackIndicatorView,并且它与基于 Auto Layout 和基于 frame 的布局都很好地协作。

使用 Auto Layout 的代码

NAKPlaybackIndicatorView *indicator = [[NAKPlaybackIndicatorView alloc] initWithFrame:CGRectZero];
indicator.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:indicator];

// Then, add some positioning layout constraints.
// Note that normally you don't need to add sizing constraints
// since NAKPlaybackIndicatorView has an intrinsic content size.
// It will be automatically resized to fit its content.

使用 Frame-Based Layout 的代码

NAKPlaybackIndicatorView *indicator = [[NAKPlaybackIndicatorView alloc] initWithFrame:CGRectZero];
[self.view addSubview:indicator];
[indicator sizeToFit]; // Resize itself to fit its content.

使用 Auto Layout 的 Storyboard

  1. 在您的视图上放一个 UIView
  2. 将其自定义类设置为 NAKPlaybackIndicatorView
  3. 大小检查器 (⌥⌘5) 中,将 内在大小 设置为 占位符 并将宽度设置为 12,高度设置为 12。请注意,这只是为了方便在 Storyboard 上的外观,占位符大小在运行时不会被使用。
  4. 添加一些定位布局约束。

使用 Frame-Based Layout 的 Storyboard

  1. 在您的视图上放一个 UIView
  2. 将其自定义类设置为 NAKPlaybackIndicatorView
  3. 大小检查器 (⌥⌘5) 中,将宽度设置为 12,高度设置为 12。

自定义

条数、大小和间距

可以通过 NAKPlaybackIndicatorViewStyle 对条进行自定义。

颜色

可以通过设置视图或其父视图的 tintColor 属性(UIView)来更改条的颜色。

视图大小

通常情况下,视图可以通过以下方式自动调整大小以适应其内容:

  • 在自动布局中省略大小约束,因为它具有内在的内容大小。
  • 在基于框架的布局中调用 sizeToFit

或者如果您显式指定大小,则条将放置在视图的中心。

类参考

NAKPlaybackIndicatorView 的类参考可在 CocoaDocs.org 上找到。

许可证

版权 (c) 2014–2017 Yuji Nakayama

有关详细信息,请参阅 LICENSE.txt